home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir37 / ms_sh23s.zip / SRC / SH.H < prev    next >
C/C++ Source or Header  |  1994-08-26  |  72KB  |  2,433 lines

  1. /*
  2.  * MS-DOS SHELL - Header File
  3.  *
  4.  * MS-DOS SHELL - Copyright (c) 1990,4 Data Logic Limited and Charles Forsyth
  5.  *
  6.  * This code is based on (in part) the shell program written by Charles
  7.  * Forsyth and the subsequence modifications made by Simon J. Gerraty (for
  8.  * his Public Domain Korn Shell) and is subject to the following copyright
  9.  * restrictions:
  10.  *
  11.  * 1.  Redistribution and use in source and binary forms are permitted
  12.  *     provided that the above copyright notice is duplicated in the
  13.  *     source form and the copyright notice in file sh6.c is displayed
  14.  *     on entry to the program.
  15.  *
  16.  * 2.  The sources (or parts thereof) or objects generated from the sources
  17.  *     (or parts of sources) cannot be sold under any circumstances.
  18.  *
  19.  *    $Header: /usr/users/istewart/shell/sh2.3/Release/RCS/sh.h,v 2.16 1994/08/25 20:58:47 istewart Exp $
  20.  *
  21.  *    $Log: sh.h,v $
  22.  *    Revision 2.16  1994/08/25  20:58:47  istewart
  23.  *    MS Shell 2.3 Release
  24.  *
  25.  *    Revision 2.15  1994/02/23  09:23:38  istewart
  26.  *    Beta 233 updates
  27.  *
  28.  *    Revision 2.14  1994/02/01  10:25:20  istewart
  29.  *    Release 2.3 Beta 2, including first NT port
  30.  *
  31.  *    Revision 2.13  1994/01/11  17:55:25  istewart
  32.  *    Release 2.3 Beta 0 patches
  33.  *
  34.  *    Revision 2.12  1993/11/09  10:39:49  istewart
  35.  *    Beta 226 checking
  36.  *
  37.  *    Revision 2.11  1993/08/25  16:03:57  istewart
  38.  *    Beta 225 - see Notes file
  39.  *
  40.  *    Revision 2.10  1993/07/02  10:25:53  istewart
  41.  *    224 Beta fixes
  42.  *
  43.  *    Revision 2.9  1993/06/14  11:00:54  istewart
  44.  *    More changes for 223 beta
  45.  *
  46.  *    Revision 2.8  1993/06/02  09:58:12  istewart
  47.  *    Shell 223 Beta Release - see Notes file
  48.  *
  49.  *    Revision 2.7  1993/02/16  16:04:22  istewart
  50.  *    Beta 2.22 Release
  51.  *
  52.  *    Revision 2.6  1993/01/26  18:35:09  istewart
  53.  *    Release 2.2 beta 0
  54.  *
  55.  *    Revision 2.5  1992/12/14  10:54:56  istewart
  56.  *    BETA 215 Fixes and 2.1 Release
  57.  *
  58.  *    Revision 2.4  1992/11/06  10:03:44  istewart
  59.  *    214 Beta test updates
  60.  *
  61.  *    Revision 2.3  1992/09/03  18:54:45  istewart
  62.  *    Beta 213 Updates
  63.  *
  64.  *    Revision 2.2  1992/07/16  14:33:34  istewart
  65.  *    Beta 212 Baseline
  66.  *
  67.  *    Revision 2.1  1992/07/14  08:58:59  istewart
  68.  *    211 Beta updates
  69.  *
  70.  *    Revision 2.0  1992/04/13  17:39:40  Ian_Stewartson
  71.  *    MS-Shell 2.0 Baseline release
  72.  *
  73.  */
  74.  
  75. /*
  76.  * Operating System Definitions
  77.  */
  78.  
  79. #define    OS_DOS        1            /* MSDOS        */
  80. #define    OS_OS2        2            /* OS/2         */
  81. #define    OS_NT        3            /* Windows NT        */
  82. #define    OS_UNIX        4            /* A UNIX system    */
  83.  
  84. #define    OS_16        1            /* 16-bit O/S        */
  85. #define    OS_32        2            /* 32-bit O/S        */
  86.  
  87. #if defined (__OS2__)
  88. #  define OS_TYPE    OS_OS2
  89. #  define OS_SIZE    OS_32
  90. #elif defined (__32BIT__) && defined (__EMX__)
  91. #  if defined (EMX_DOS)
  92. #    define OS_TYPE    OS_DOS
  93. #  else
  94. #    define OS_TYPE    OS_OS2
  95. #  endif
  96. #  define OS_SIZE    OS_32
  97. #elif defined (OS2)
  98. #  define OS_TYPE    OS_OS2
  99. #  define OS_SIZE    OS_16
  100. #elif defined (WIN32)
  101. #  define OS_TYPE    OS_NT
  102. #  define OS_SIZE    OS_32
  103. #elif defined (__386__)
  104. #  define OS_TYPE    OS_DOS
  105. #  define OS_SIZE    OS_32
  106. #elif defined (unix)
  107. #  define OS_TYPE    OS_UNIX
  108. #  define OS_SIZE    OS_32
  109. #else
  110. #  define OS_TYPE    OS_DOS
  111. #  define OS_SIZE    OS_16
  112. #  define OS_SWAPPING    1
  113. #endif
  114.  
  115. #if (OS_SIZE == OS_32)
  116. #  define F_LOCAL
  117. #else
  118. #  define F_LOCAL    near
  119. #endif
  120.  
  121. /*
  122.  * Get the system include files
  123.  */
  124.  
  125. #if (OS_TYPE == OS_OS2)
  126.  
  127. /*
  128.  * OS/2 Stuff.  Define the following so we get the right defs.
  129.  */
  130.  
  131. #  define INCL_DOSDEVICES
  132. #  define INCL_DOSERRORS
  133. #  define INCL_DOSEXCEPTIONS
  134. #  define INCL_DOSFILEMGR
  135. #  define INCL_DOSMEMMGR
  136. #  define INCL_DOSMISC
  137. #  define INCL_DOSMODULEMGR
  138. #  define INCL_DOSPROCESS
  139. #  define INCL_DOSQUEUES
  140. #  define INCL_DOSSEMAPHORES
  141. #  define INCL_DOSSESMGR
  142. #  define INCL_DOSSIGNALS
  143. #  define INCL_KBD
  144. #  define INCL_VIO
  145. #  define INCL_WINSWITCHLIST
  146.  
  147. #  include <os2.h>
  148. #  include <bseerr.h>
  149.  
  150. #  if (OS_SIZE == OS_32)
  151. #    include <bsedev.h>
  152.  
  153. /* Some compilers miss the 1.x to 2.x conversion macros */
  154.  
  155. #    ifndef DosCwait
  156. #      define DosCwait            DosWaitChild
  157. #    endif
  158.  
  159. #    ifndef DosQCurDisk
  160. #      define DosQCurDisk        DosQueryCurrentDisk
  161. #    endif
  162.  
  163. #    ifndef DosQFSAttach
  164. #      define DosQFSAttach        DosQueryFSAttach
  165. #    endif
  166.  
  167. #    ifndef DosQFSInfo
  168. #      define DosQFSInfo        DosQueryFSInfo
  169. #    endif
  170.  
  171. #    ifndef DosQHandType
  172. #      define DosQHandType        DosQueryHType
  173. #    endif
  174.  
  175. #    ifndef DosQVerify
  176. #      define DosQVerify        DosQueryVerify
  177. #    endif
  178.  
  179. #    ifndef DosSelectDisk
  180. #      define DosSelectDisk        DosSetDefaultDisk
  181. #    endif
  182.  
  183. #    ifndef DosSetFHandState
  184. #      define DosSetFHandState        DosSetFHState
  185. #    endif
  186.  
  187. #    ifndef DosQFileInfo
  188. #      define DosQFileInfo        DosQueryFileInfo
  189. #    endif
  190.  
  191. #  endif
  192.  
  193. #elif (OS_TYPE == OS_NT)
  194.  
  195. /*
  196.  * Windows NT Stuff.  Define the following so we don't get tons of extra stuff
  197.  * when we include windows.h 
  198.  */
  199.  
  200. #  define NOGDICAPMASKS     
  201. #  define NOVIRTUALKEYCODES 
  202. #  define NOWINMESSAGES     
  203. #  define NOWINSTYLES       
  204. #  define NOSYSMETRICS      
  205. #  define NOMENUS           
  206. #  define NOICONS           
  207. #  define NOKEYSTATES       
  208. #  define NOSYSCOMMANDS     
  209. #  define NORASTEROPS       
  210. #  define NOSHOWWINDOW      
  211. #  define OEMRESOURCE       
  212. #  define NOATOM            
  213. #  define NOCLIPBOARD       
  214. #  define NOCOLOR           
  215. #  define NOCTLMGR          
  216. #  define NODRAWTEXT        
  217. #  define NOGDI             
  218. /* #  define NOKERNEL         */
  219. /* #  define NOUSER           */
  220. #  define NONLS             
  221. #  define NOMB              
  222. #  define NOMEMMGR          
  223. #  define NOMETAFILE        
  224. #  define NOMINMAX          
  225. #  define NOMSG             
  226. #  define NOOPENFILE        
  227. #  define NOSCROLL          
  228. #  define NOSERVICE         
  229. #  define NOSOUND           
  230. #  define NOTEXTMETRIC      
  231. #  define NOWH              
  232. #  define NOWINOFFSETS      
  233. #  define NOCOMM            
  234. #  define NOKANJI           
  235. #  define NOHELP            
  236. #  define NOPROFILER        
  237. #  define NODEFERWINDOWPOS  
  238.  
  239. /*
  240.  * We're not using Microsoft's "extensions" to C for Structured Exception
  241.  * Handling (SEH).
  242.  */
  243.  
  244. #  undef try
  245. #  undef except
  246. #  undef finally
  247. #  undef leave
  248.  
  249. #  include <windows.h>
  250.  
  251. #elif (OS_TYPE == OS_DOS)
  252.  
  253. /* Finally the DOS stuff */
  254.  
  255. #  include <dos.h>
  256. #  if defined (__32BIT__) && defined (__EMX__)
  257.  
  258. #  else
  259. #    include <bios.h>
  260. #  endif
  261.  
  262. /* Add bool definitions and others for UNIX */
  263.  
  264. #elif (OS_TYPE == OS_UNIX) 
  265. typedef pid_t         PID;
  266. #endif
  267.  
  268. #if defined (__EMX__) && (OS_TYPE == OS_OS2)
  269. typedef PID         pid_t;
  270. #endif
  271.  
  272. #ifndef _BOOL_T_DEFINED
  273. typedef unsigned char    bool;
  274. #  define _BOOL_T_DEFINED
  275. #endif
  276.  
  277. #ifndef TRUE
  278. #  define TRUE    ((bool)1)
  279. #endif
  280.  
  281. #ifndef FALSE
  282. #  define FALSE    ((bool)0)
  283. #endif
  284.  
  285.  
  286. /*
  287.  * Define number of signals
  288.  */
  289.  
  290. #ifndef NSIG
  291. #  define NSIG    10
  292. #endif
  293.  
  294. /*
  295.  * Flags to DosFlagProcess are missing on IBM C Set/2
  296.  */
  297.  
  298. #ifndef PFLG_A
  299. #  define PFLG_A    0    /* Process Flag A            */
  300. #endif
  301.  
  302. #ifndef PFLG_B
  303. #  define PFLG_B    1    /* Process Flag B            */
  304. #endif
  305.  
  306. #ifndef PFLG_C
  307. #  define PFLG_C    2    /* Process Flag C            */
  308. #endif
  309.  
  310. /*
  311.  * DosFlagProcess codes
  312.  */
  313.  
  314. #ifndef FLGP_SUBTREE
  315. #  define FLGP_SUBTREE    0    /* All sub-tree processes        */
  316. #endif
  317.  
  318. #ifndef FLGP_PID
  319. #  define FLGP_PID    1    /* only the process            */
  320. #endif
  321.  
  322. /*
  323.  * Spawn Types
  324.  */
  325.  
  326. #ifndef P_WAIT
  327. #  define P_WAIT      0
  328. #endif
  329.  
  330. #ifndef P_NOWAIT
  331. #  define P_NOWAIT    1
  332. #endif
  333.  
  334. #ifndef P_OVERLAY
  335. #  define P_OVERLAY    2
  336. #endif
  337.  
  338. #ifndef OLD_P_OVERLAY
  339. #  define OLD_P_OVERLAY    2
  340. #endif
  341.  
  342. #ifndef P_NOWAITO
  343. #  define P_NOWAITO    3
  344. #endif
  345.  
  346. #ifndef P_DETACH
  347. #  define P_DETACH    4
  348. #endif
  349.  
  350. /* Wait values */
  351.  
  352. #ifndef WAIT_CHILD
  353. #  define WAIT_CHILD        0
  354. #endif
  355.  
  356. #ifndef WAIT_GRANDCHILD
  357. #  define WAIT_GRANDCHILD    1
  358. #endif
  359. /*
  360.  * Missing errno values
  361.  */
  362.  
  363. #ifndef EIO
  364. #  define EIO        105    /* I/O error                */
  365. #endif
  366.  
  367. #ifndef E2BIG
  368. #  define E2BIG        107    /* Arg list too long            */
  369. #endif
  370.  
  371. #ifndef ENOTDIR
  372. #  define ENOTDIR    120    /* Not a directory            */
  373. #endif
  374.  
  375. /*
  376.  * Missing stat definitions
  377.  */
  378.  
  379. #ifndef S_IFMT
  380. #  define    S_IFMT    0xf000    /* type of file                */
  381. #endif
  382.  
  383. #ifndef S_IFBLK
  384. #  define    S_IFBLK    0x6000    /* block special            */
  385. #endif
  386.  
  387. #ifndef S_ISDIR
  388. #  define S_ISDIR(m)    ((((m) & S_IFMT) == S_IFDIR))
  389. #endif
  390.  
  391. #ifndef S_ISCHR
  392. #  define S_ISCHR(m)    ((((m) & S_IFMT) == S_IFCHR))
  393. #endif
  394.  
  395. #ifndef S_ISREG
  396. #  define S_ISREG(m)    ((((m) & S_IFMT) == S_IFREG))
  397. #endif
  398.  
  399. #ifndef S_ISBLK
  400. #  define S_ISBLK(m)    ((((m) & S_IFMT) == S_IFBLK))
  401. #endif
  402.  
  403. /* GCC has these missing */
  404.  
  405. #ifndef min
  406. #  define min(a,b)             (((a) < (b)) ? (a) : (b))
  407. #endif
  408.  
  409. #ifndef O_TEXT
  410. #  define O_TEXT        0
  411. #endif
  412.  
  413. #ifndef O_BINARY
  414. #  define O_BINARY        0
  415. #endif
  416.  
  417. #ifndef O_NOINHERIT
  418. #  define O_NOINHERIT        0x8000
  419. #endif
  420.  
  421. #ifndef CLOCKS_PER_SEC
  422. #  define CLOCKS_PER_SEC    1000
  423. #endif
  424.  
  425. #ifndef max
  426. #  define max(a,b)     (((a) > (b)) ? (a) : (b))
  427. #endif
  428.  
  429. /*
  430.  * File Attributes
  431.  */
  432.  
  433. #if defined (__TURBOC__)
  434. #  define OS_FILE_DIRECTORY        FA_DIREC
  435. #  define OS_FILE_HIDDEN        FA_HIDDEN
  436. #  define OS_FILE_SYSTEM         FA_SYSTEM
  437. #  define OS_FILE_NORMAL        0
  438. #  define OS_FILE_READONLY        FA_RDONLY
  439. #  define OS_FILE_ARCHIVED        FA_ARCH
  440.  
  441. /* TurboC puts this in io.h, which we don't include */
  442.  
  443. extern int  _Cdecl            _chmod (const char *, int, ...);
  444. #  define OS_GetFileAttributes(a,b)    (*b = _chmod ((a), 0))
  445.  
  446. #elif (OS_TYPE == OS_DOS)
  447.  
  448. #  define OS_FILE_DIRECTORY        _A_SUBDIR
  449. #  define OS_FILE_HIDDEN        _A_HIDDEN
  450. #  define OS_FILE_SYSTEM         _A_SYSTEM
  451. #  define OS_FILE_NORMAL        _A_NORMAL
  452. #  define OS_FILE_READONLY        _A_RDONLY
  453. #  define OS_FILE_ARCHIVED        _A_ARCH
  454.  
  455. #  ifndef _A_NORMAL
  456. #    define _A_NORMAL    0x00        /* No attributes        */
  457. #  endif
  458. #  ifndef _A_RDONLY
  459. #    define _A_RDONLY    0x01        /* Read-only            */
  460. #  endif
  461. #  ifndef _A_HIDDEN
  462. #    define _A_HIDDEN    0x02        /* Hidden            */
  463. #  endif
  464. #  ifndef _A_SYSTEM
  465. #    define _A_SYSTEM    0x04        /* System            */
  466. #  endif
  467. #  ifndef _A_VOLID
  468. #    define _A_VOLID    0x08        /* Volume label            */
  469. #  endif
  470. #  ifndef _A_SUBDIR
  471. #    define _A_SUBDIR    0x10        /* Directory            */
  472. #  endif
  473. #  ifndef _A_ARCH
  474. #    define _A_ARCH    0x20        /* Archive            */
  475. #  endif
  476. #  ifndef _A_DEVICE
  477. #    define _A_DEVICE    0x40        /* Device            */
  478. #  endif
  479.  
  480. #  define OS_GetFileAttributes(a,b)    _dos_getfileattr ((a), (b))
  481.  
  482. #elif (OS_TYPE == OS_OS2)
  483.  
  484. #  define OS_FILE_DIRECTORY        FILE_DIRECTORY
  485. #  define OS_FILE_HIDDEN        FILE_HIDDEN
  486. #  define OS_FILE_SYSTEM        FILE_SYSTEM
  487. #  define OS_FILE_NORMAL        FILE_NORMAL
  488. #  define OS_FILE_READONLY        FILE_READONLY
  489. #  define OS_FILE_ARCHIVED        FILE_ARCHIVED
  490.  
  491. #  if (OS_SIZE == OS_16)
  492. #    define OS_GetFileAttributes(a,b)    DosQFileMode ((a), (b), 0L)
  493. #  else
  494. #    define OS_GetFileAttributes(a,b)    DosQFileMode ((a), (b))
  495. #  endif
  496.  
  497. #elif (OS_TYPE == OS_NT)
  498.  
  499. #  define OS_FILE_DIRECTORY        FILE_ATTRIBUTE_DIRECTORY
  500. #  define OS_FILE_HIDDEN        FILE_ATTRIBUTE_HIDDEN
  501. #  define OS_FILE_SYSTEM        FILE_ATTRIBUTE_SYSTEM
  502. #  define OS_FILE_NORMAL        0
  503. #  define OS_FILE_READONLY        FILE_ATTRIBUTE_READONLY
  504. #  define OS_FILE_ARCHIVED        FILE_ATTRIBUTE_ARCHIVE
  505.  
  506. #  define OS_GetFileAttributes(a,b)    DosQFileMode ((a), (b))
  507. #endif
  508.  
  509. #define OS_FILE_ATTRIBUTES    (OS_FILE_DIRECTORY | OS_FILE_HIDDEN | \
  510.                  OS_FILE_SYSTEM    | OS_FILE_NORMAL | \
  511.                  OS_FILE_READONLY  | OS_FILE_ARCHIVED)
  512.  
  513. /*
  514.  * Get major version number
  515.  */
  516.  
  517. #if (OS_TYPE == OS_OS2)
  518. #  define OS_VERS_N        _osmajor / 10
  519. #else
  520. #  define OS_VERS_N        _osmajor
  521. #endif
  522.  
  523. extern int    BaseOS;        /* Underlying OS            */
  524.  
  525. #define BASE_OS_DOS    0    /* DOS                    */
  526. #define BASE_OS_WIN    1    /* Windows                */
  527. #define BASE_OS_OS2    2    /* OS2                    */
  528. #define BASE_OS_NT    3    /* Windows NT                */
  529. #define BASE_OS_UNIX    4    /* UNIX                    */
  530.  
  531. /*
  532.  * Watcom does something funny in 386 mode with registers and int86
  533.  */
  534.  
  535. #if (OS_TYPE == OS_DOS)
  536. #  if defined (__WATCOMC__) && defined(__386__) && !defined(__WINDOWS_386__)
  537. #    define REG_AX                eax
  538. #    define REG_BX                ebx
  539. #    define REG_CX                ecx
  540. #    define REG_DX                edx
  541. #    define REG_SI                esi
  542. #    define REG_DI                edi
  543. #    define REG_CFLAGS                cflag
  544. #    define SystemInterrupt(a,b,c)        int386 (a, b, c)
  545. #    define SystemExtendedInterrupt(a,b,c,d)    int386x (a, b, c, d)
  546. #    define DosInterrupt(a,b)            intdos (a, b)
  547. #    define DosExtendedInterrupt(a,b,c)        intdosx (a, b, c)
  548. #  elif defined (__EMX__)
  549. #    define REG_AX                ax
  550. #    define REG_BX                bx
  551. #    define REG_CX                cx
  552. #    define REG_DX                dx
  553. #    define REG_SI                si
  554. #    define REG_DI                di
  555. #    define REG_CFLAGS                flags
  556. #    define SystemInterrupt(a,b,c)        _int86 (a, b, c)
  557. #    define SystemExtendedInterrupt(a,b,c,d)    not available
  558. #    define DosInterrupt(a,b)            _int86 (0x21, a, b)
  559. #    define DosExtendedInterrupt(a,b,c)        intdosx (a, b, c)
  560. #  else
  561. #    define REG_AX                ax
  562. #    define REG_BX                bx
  563. #    define REG_CX                cx
  564. #    define REG_DX                dx
  565. #    define REG_SI                si
  566. #    define REG_DI                di
  567. #    define REG_CFLAGS                cflag
  568. #    define SystemInterrupt(a,b,c)        int86 (a, b, c)
  569. #    define SystemExtendedInterrupt(a,b,c,d)    int86x (a, b, c, d)
  570. #    define DosInterrupt(a,b)            intdos (a, b)
  571. #    define DosExtendedInterrupt(a,b,c)        intdosx (a, b, c)
  572. #  endif
  573. #endif
  574.  
  575. /*
  576.  * Missing OS/2 1.x definitions.  Map OS/2 2.x definitions as appropriate
  577.  */
  578.  
  579. #if (OS_TYPE == OS_OS2) && (OS_SIZE == OS_16)
  580. #  define SSF_RELATED_INDEPENDENT    0    /* New session is an    */
  581.                     /* independent            */
  582.                     /* session (not related)    */
  583. #  define SSF_RELATED_CHILD    1    /* New session is a child    */
  584.                     /* session (related)        */
  585. #  define SSF_FGBG_FORE        0    /* Start session in foreground    */
  586. #  define SSF_FGBG_BACK        1    /* Start session in background    */
  587. #  define SSF_TRACEOPT_NONE    0    /* No trace            */
  588. #  define SSF_TRACEOPT_TRACE    1    /* Trace with no notification    */
  589.                     /* of descendants        */
  590. #  define SSF_TRACEOPT_TRACEALL    2    /* Trace all descendant sessions */
  591. #  define SSF_INHERTOPT_SHELL    0    /* Inherit the Shell's environment.*/
  592. #  define SSF_INHERTOPT_PARENT    1    /* Inherit the environment of the*/
  593.                     /* program issuing the        */
  594.                     /* DosStartSession call.    */
  595. #  define SSF_TYPE_DEFAULT    0    /* Use the PgmHandle data, or    */
  596.                     /* allow the Shell to establish    */
  597.                     /* the session type.        */
  598. #  define SSF_TYPE_FULLSCREEN    1    /* Start the program in a    */
  599.                     /* full-screen session.        */
  600. #  define SSF_TYPE_WINDOWABLEVIO    2    /* Start the program    */
  601.                     /* in a    windowed session for    */
  602.                     /* programs using the Base Video*/
  603.                     /* Subsystem            */
  604. #  define SSF_TYPE_PM        3    /* Start the program in a    */
  605.                     /* windowed session for programs*/
  606.                     /* using the Presentation Manager*/
  607.                     /* services            */
  608. #  define SSF_TYPE_VDM        4    /* Start the program in a    */
  609.                     /* full-screen DOS session.    */
  610. #  define SSF_TYPE_WINDOWEDVDM    7    /* Start the program in a    */
  611.                     /* windowed DOS session.    */
  612. #  define SSF_CONTROL_VISIBLE    0x0000    /* Visible            */
  613. #  define SSF_CONTROL_INVISIBLE    0x0001    /* Invisible            */
  614. #  define SSF_CONTROL_MAXIMIZE    0x0002    /* Maximize            */
  615. #  define SSF_CONTROL_MINIMIZE    0x0004    /* Minimize            */
  616. #  define SSF_CONTROL_NOAUTOCLOSE    0x0008    /* No Auto Close    */
  617. #  define SSF_CONTROL_SETPOS    0x8000    /* Use specified size and position */
  618. #endif
  619.  
  620. /*
  621.  * Define common OS2 APIs declaractions
  622.  */
  623.  
  624. #if (OS_TYPE == OS_OS2)
  625. #  if (OS_SIZE == OS_16)
  626. #    define OSCALL_RET        USHORT
  627. #    define OSCALL_PARAM    USHORT
  628. #  else
  629. #    define OSCALL_RET        APIRET
  630. #    define OSCALL_PARAM    ULONG
  631. #  endif
  632. #elif (OS_TYPE == OS_DOS)
  633. #  define OSCALL_RET        unsigned int
  634. #  define OSCALL_PARAM        unsigned int
  635. #elif (OS_TYPE == OS_NT)
  636. #  define OSCALL_RET        DWORD
  637. #  define OSCALL_PARAM        DWORD
  638. #elif (OS_TYPE == OS_UNIX)
  639. #  define OSCALL_RET        int
  640. #  define OSCALL_PARAM        int
  641. #endif
  642.  
  643. /*
  644.  * Borland TurboC has this in a file we don't include
  645.  */
  646.  
  647. #ifdef __TURBOC__
  648. #  define getpid()    (_psp)
  649. #endif
  650.  
  651. /*
  652.  * UNIX doesn't have these functions
  653.  */
  654.  
  655. #if (OS_TYPE == OS_UNIX)
  656. extern char            *strlwr (char *);
  657. extern char            *strupr (char *);
  658. extern int            stricmp (char *, char *);
  659. #  define fputchar(c)        putchar (c)
  660. #endif
  661.  
  662. /*
  663.  * Ignore case compare.  UNIX cares about case!
  664.  */
  665.  
  666. #if (OS_TYPE == OS_UNIX)
  667. #  define NOCASE_COMPARE(a,b)    strcmp (a,b)
  668. #else
  669. #  define NOCASE_COMPARE(a,b)    stricmp (a,b)
  670. #endif
  671.  
  672. /*
  673.  * Executable Head Information structures
  674.  *
  675.  * Variable signatures
  676.  */
  677.  
  678. #define SIG_DOS        0x5a4d        /* Dos Magic number        */
  679. #define SIG_OS2_16    0x454e        /* OS/2 16 Magic number        */
  680. #define SIG_OS2_16LE    0x454c        /* OS/2 16 Magic number        */
  681. #define SIG_OS2_32    0x584c        /* OS/2 32 Magic number        */
  682. #define SIG_NT        0x00004550    /* NT Magic number        */
  683.  
  684. /*
  685.  * Standard DOS header
  686.  */
  687.  
  688. #pragma pack (1)
  689.  
  690. struct ExecDosHeader {
  691.     unsigned short    e_magic;    /* Magic number            */
  692.     unsigned short    e_cblp;        /* Bytes on last page of file    */
  693.     unsigned short    e_cp;        /* Pages in file        */
  694.     unsigned short    e_crlc;        /* Relocations            */
  695.     unsigned short    e_cparhdr;    /* Size of header in paragraphs */
  696.     unsigned short    e_minalloc;    /* Minimum extra paras needed    */
  697.     unsigned short    e_maxalloc;    /* Maximum extra paras needed    */
  698.     unsigned short    e_ss;        /* Initial (relative) SS value    */
  699.     unsigned short    e_sp;        /* Initial SP value        */
  700.     unsigned short    e_csum;        /* Checksum            */
  701.     unsigned short    e_ip;        /* Initial IP value        */
  702.     unsigned short    e_cs;        /* Initial (relative) CS value    */
  703.     unsigned short    e_lfarlc;    /* File addr. of reloc. table    */
  704.     unsigned short    e_ovno;        /* Overlay number        */
  705.     unsigned short    e_res[4];    /* Reserved words        */
  706.     unsigned short    e_oemid;    /* OEM identifier        */
  707.     unsigned short    e_oeminfo;    /* OEM information        */
  708.     unsigned short    e_res2[10];    /* Reserved words        */
  709.     long        e_lfanew;    /* File addr of new exe header    */
  710. };
  711.  
  712. /*
  713.  * OS/2 and Windows 16 Bit header
  714.  */
  715.  
  716. struct ExecOS2_16Header {
  717.     unsigned short    ne_magic;    /* Magic number            */
  718.     unsigned char    ne_ver;        /* Version number        */
  719.     unsigned char    ne_rev;        /* Revision number        */
  720.     unsigned short    ne_enttab;    /* Offset of Entry Table    */
  721.     unsigned short    ne_cbenttab;    /* Size of Entry Table        */
  722.     long        ne_crc;        /* Checksum of whole file    */
  723.     unsigned short    ne_flags;    /* Flag word            */
  724.     unsigned short    ne_autodata;    /* Automatic data segment number*/
  725.     unsigned short    ne_heap;    /* Initial heap allocation    */
  726.     unsigned short    ne_stack;    /* Initial stack allocation    */
  727.     long        ne_csip;    /* Initial CS:IP setting    */
  728.     long        ne_sssp;    /* Initial SS:SP setting    */
  729.     unsigned short    ne_cseg;    /* Count of file segments    */
  730.     unsigned short    ne_cmod;    /* Entries in Module Ref. Table    */
  731.     unsigned short    ne_cbnrestab;    /* Size non-resident name table    */
  732.     unsigned short    ne_segtab;    /* Off. Segment Table        */
  733.     unsigned short    ne_rsrctab;    /* Off. Resource Table        */
  734.     unsigned short    ne_restab;    /* Off. resident name table    */
  735.     unsigned short    ne_modtab;    /* Off. Module Reference Table    */
  736.     unsigned short    ne_imptab;    /* Off. Imported Names Table    */
  737.     long        ne_nrestab;    /* Off. Non-resident Names Table*/
  738.     unsigned short    ne_cmovent;    /* Count of movable entries    */
  739.     unsigned short    ne_align;    /* Segment alignment shift count*/
  740.     unsigned short    ne_cres;    /* Count of resource segments    */
  741.     unsigned char    ne_exetyp;    /* Target Operating system    */
  742.     unsigned char    ne_flagsothers;    /* Other .EXE flags        */
  743.     unsigned short    ne_pretthunks;    /* offset to return thunks    */
  744.     unsigned short    ne_psegrefbytes;/* offset to segment ref. bytes    */
  745.     unsigned short    ne_swaparea;    /* Minimum code swap area size    */
  746.     unsigned short    ne_expver;    /* Expected Windows version number */
  747. };
  748.  
  749. /*
  750.  * Selected ne_flags values
  751.  */
  752.  
  753. #define OS2_16_NOTP        0x8000    /* Not a process        */
  754. #define OS2_16_IERR        0x2000    /* Errors in image        */
  755. #define OS2_16_BOUND        0x0800    /* Bound Family/API        */
  756. #define OS2_16_APPTYP        0x0700    /* Application type mask    */
  757. #define OS2_16_NOTWINCOMPAT    0x0100    /* Not compatible with P.M. Windowing */
  758. #define OS2_16_WINCOMPAT    0x0200    /* Compatible with P.M. Windowing */
  759. #define OS2_16_WINAPI        0x0300    /* Uses P.M. Windowing API    */
  760.  
  761. /*
  762.  * ne_exetyp values
  763.  */
  764.  
  765. #define OS2_16_UNKNOWN        0    /* Unknown (any "new-format" OS) */
  766. #define OS2_16_OS2        1    /* OS/2 (default)        */
  767. #define OS2_16_WINDOWS        2    /* Windows            */
  768. #define OS2_16_DOS4        3    /* DOS 4.x            */
  769. #define OS2_16_DEV386        4    /* Windows 386            */
  770.  
  771. /*
  772.  * OS2 32bit header
  773.  */
  774.  
  775. struct ExecOS2_32header {
  776.     unsigned short    e32_magic;    /* Magic number OS2__MAGIC    */
  777.     unsigned char    e32_border;    /* Byte ordering for the .EXE    */
  778.     unsigned char    e32_worder;    /* Word ordering for the .EXE    */
  779.     unsigned long    e32_level;    /* EXE format level for now = 0    */
  780.     unsigned short    e32_cpu;    /* CPU type            */
  781.     unsigned short    e32_os;        /* OS type            */
  782.     unsigned long    e32_ver;    /* Module version        */
  783.     unsigned long    e32_mflags;    /* Module flags            */
  784.     unsigned long    e32_mpages;    /* Module # pages        */
  785.     unsigned long    e32_startobj;    /* Object # for IP        */
  786.     unsigned long    e32_eip;    /* Extended IP            */
  787.     unsigned long    e32_stackobj;    /* Object # for SS        */
  788.     unsigned long    e32_esp;    /* Extended SS            */
  789.     unsigned long    e32_pagesize;    /* .EXE page size        */
  790.     unsigned long    e32_pageshift;    /* Page alignment shift in .EXE    */
  791.     unsigned long    e32_fixupsize;    /* Fixup section size        */
  792.     unsigned long    e32_fixupsum;    /* Fixup section checksum    */
  793.     unsigned long    e32_ldrsize;    /* Loader section size        */
  794.     unsigned long    e32_ldrsum;    /* Loader section checksum    */
  795.     unsigned long    e32_objtab;    /* Object table off.        */
  796.     unsigned long    e32_objcnt;    /* Number of objects in module    */
  797.     unsigned long    e32_objmap;    /* Object page map off.        */
  798.     unsigned long    e32_itermap;    /* Object iterated data map off. */
  799.     unsigned long    e32_rsrctab;    /* Off. Resource Table        */
  800.     unsigned long    e32_rsrccnt;    /* Number of resource entries    */
  801.     unsigned long    e32_restab;    /* Off. resident name table    */
  802.     unsigned long    e32_enttab;    /* Off. Entry Table        */
  803.     unsigned long    e32_dirtab;    /* Off. Module Directive Table    */
  804.     unsigned long    e32_dircnt;    /* Number of module directives    */
  805.     unsigned long    e32_fpagetab;    /* Off. Fixup Page Table    */
  806.     unsigned long    e32_frectab;    /* Off. Fixup Record Table    */
  807.     unsigned long    e32_impmod;    /* Off. Import Module Name Table */
  808.     unsigned long    e32_impmodcnt;    /* # entries in IM Name Table    */
  809.     unsigned long    e32_impproc;    /* Off. IProcedure Name Table    */
  810.     unsigned long    e32_pagesum;    /* Off. Per-Page Checksum Table    */
  811.     unsigned long    e32_datapage;    /* Off. Enumerated Data Pages    */
  812.     unsigned long    e32_preload;    /* Number of preload pages    */
  813.     unsigned long    e32_nrestab;    /* Off. Non-resident Names Table */
  814.     unsigned long    e32_cbnrestab;    /* Size of Non-resident Name Table */
  815.     unsigned long    e32_nressum;    /* Non-resident Name Table Checksum */
  816.     unsigned long    e32_autodata;    /* Object # for automatic data object */
  817.     unsigned long    e32_debuginfo;    /* Off. the debugging information */
  818.     unsigned long    e32_debuglen;    /* Length of debugging info.    */
  819.     unsigned long    e32_instpreload;/* # instance pages in preload    */
  820.                         /* section of .EXE file        */
  821.     unsigned long    e32_instdemand;    /* # instance pages in demand    */
  822.                         /* load section of .EXE file    */
  823.     unsigned long    e32_heapsize;    /* Size of heap - for 16-bit apps */
  824. /* Padding ignored */
  825. };
  826.  
  827. /*
  828.  * Format of e32_mflags
  829.  */
  830.  
  831. #define OS2_NOTP    0x00008000L    /* Library Module - used as NENOTP */
  832. #define OS2_NOLOAD    0x00002000L    /* Module not Loadable        */
  833. #define OS2_PMAPI    0x00000300L    /* Uses PM Windowing API    */
  834. #define OS2_PMW        0x00000200L    /* Compatible with PM Windowing */
  835. #define OS2_NOPMW    0x00000100L    /* Incompatible with PM Windowing */
  836. #define OS2_APPMASK    0x00000700L    /* Application Type Mask    */
  837. #define OS2_PROTDLL    0x00010000L    /* Protected memory library module */
  838. #define OS2_DEVICE    0x00020000L    /* Device driver        */
  839. #define OS2_MODEXE    0x00000000L    /* .EXE module            */
  840. #define OS2_MODDLL    0x00008000L    /* .DLL module            */
  841. #define OS2_MODPROTDLL    0x00018000L    /* Protected memory library module */
  842. #define OS2_MODPDEV    0x00020000L    /* Physical device driver    */
  843. #define OS2_MODVDEV    0x00028000L    /* Virtual device driver    */
  844. #define OS2_MODMASK    0x00038000L    /* Module type mask        */
  845.  
  846. /*
  847.  * NT Exec Header
  848.  */
  849.  
  850. struct ExecNTHeader {
  851.     unsigned long        Signature;
  852.  
  853.     struct NTFileHeader {
  854.     unsigned short        Machine;
  855.     unsigned short        NumberOfSections;
  856.     unsigned long        TimeDateStamp;
  857.     unsigned long        PointerToSymbolTable;
  858.     unsigned long        NumberOfSymbols;
  859.     unsigned short        SizeOfOptionalHeader;
  860.     unsigned short        Characteristics;
  861.     }                FileHeader;
  862.  
  863.     struct NTOptionalHeader {
  864.     unsigned short        Magic;
  865.     unsigned char        MajorLinkerVersion;
  866.     unsigned char        MinorLinkerVersion;
  867.     unsigned long        SizeOfCode;
  868.     unsigned long        SizeOfInitializedData;
  869.     unsigned long        SizeOfUninitializedData;
  870.     unsigned long        AddressOfEntryPoint;
  871.     unsigned long        BaseOfCode;
  872.     unsigned long        BaseOfData;
  873.     unsigned long        ImageBase;
  874.     unsigned long        SectionAlignment;
  875.     unsigned long        FileAlignment;
  876.     unsigned short        MajorOperatingSystemVersion;
  877.     unsigned short        MinorOperatingSystemVersion;
  878.     unsigned short        MajorImageVersion;
  879.     unsigned short        MinorImageVersion;
  880.     unsigned short        MajorSubsystemVersion;
  881.     unsigned short        MinorSubsystemVersion;
  882.     unsigned long        Reserved1;
  883.     unsigned long        SizeOfImage;
  884.     unsigned long        SizeOfHeaders;
  885.     unsigned long        CheckSum;
  886.     unsigned short        Subsystem;
  887.     unsigned short        DllCharacteristics;
  888.     unsigned long        SizeOfStackReserve;
  889.     unsigned long        SizeOfStackCommit;
  890.     unsigned long        SizeOfHeapReserve;
  891.     unsigned long        SizeOfHeapCommit;
  892.     unsigned long        LoaderFlags;
  893.     unsigned long        NumberOfRvaAndSizes;
  894. /* All entries after this left out */
  895.     }                OptionalHeader;
  896. };
  897.  
  898. #pragma pack ()
  899.  
  900. /*
  901.  * NT header definitions
  902.  */
  903.  
  904. #define NT_STD_HEADER        28    /* Size of Standard header    */
  905. #define NT_OPTIONAL_HEADER    224    /* Size of Optional header    */
  906.  
  907. #define NT_FILE_DLL        0x2000        /* File is a DLL.    */
  908. #define NT_FILE_MACHINE_I386    0x14c        /* Intel 386.        */
  909.  
  910. /* Subsystem Values */
  911.  
  912. #define NT_SS_NATIVE        1    /* doesn't require a subsystem.    */
  913. #define NT_SS_WINDOWS_GUI    2    /* Windows GUI subsystem.    */
  914. #define NT_SS_WINDOWS_CUI    3    /* Windows character subsystem.    */
  915. #define NT_SS_OS2_CUI        5    /* OS/2 character subsystem.    */
  916. #define NT_SS_POSIX_CUI        7    /* Posix character subsystem.    */
  917.  
  918. /*
  919.  * Find the application type
  920.  */
  921.  
  922. extern unsigned long        QueryApplicationType (const char *);
  923.  
  924. /* Result from above */
  925.  
  926. #define EXETYPE_ERROR        0x00000f    /* Error on program    */
  927. #define EXETYPE_DOS        0x0000f0    /* Dos program        */
  928. #define EXETYPE_OS2        0x000f00    /* OS/2 16 program    */
  929. #define EXETYPE_OS2_TYPE    0x000700    /* OS/2 Type program    */
  930. #define EXETYPE_OS2_32        0x000800    /* OS/2 32 program    */
  931. #define EXETYPE_NT        0x00f000    /* Win NT program    */
  932. #define EXETYPE_UNIX        0x0f0000    /* UNIX program        */
  933.  
  934. #define EXETYPE_UNKNOWN        0x000001    /* Not known        */
  935. #define EXETYPE_BAD_IMAGE    0x000002    /* Bad image          */
  936. #define EXETYPE_NOT_EXE        0x000003    /* Not exe - OS/2    */
  937. #define EXETYPE_BAD_FILE    0x000004    /* File not found    */
  938.  
  939. #define EXETYPE_DOS_CUI        0x000010    /* Dos non windows    */
  940. #define EXETYPE_DOS_GUI        0x000020    /* Windows        */
  941. #define EXETYPE_DOS_32        0x000030    /* Watcom 32 bit    */
  942. #define EXETYPE_DOS_BOUND    0x000040    /* OS/2 Bound         */
  943.  
  944. #define EXETYPE_OS2_CUI        0x000100    /* Not windows compat    */
  945. #define EXETYPE_OS2_CGUI    0x000200    /* Windows compatible    */
  946. #define EXETYPE_OS2_GUI        0x000300    /* Uses PM        */
  947.  
  948. #define EXETYPE_NT_NATIVE    0x001000    /* NT native        */
  949. #define EXETYPE_NT_WINDOWS_GUI    0x002000    /* NT Windows GUI ss    */
  950. #define EXETYPE_NT_WINDOWS_CUI    0x003000    /* NT Windows CUI ss    */
  951. #define EXETYPE_NT_OS2        0x004000    /* NT OS2 subsystem    */
  952. #define EXETYPE_NT_POSIX    0x005000    /* NT POSIX subsystem    */
  953.  
  954. #define EXETYPE_UNIX_NATIVE    0x010000    /* UNIX program        */
  955.  
  956. /*
  957.  * Shell Definitions
  958.  */
  959.  
  960. #define PATCHLEVEL        4
  961. #define    LINE_MAX        1000    /* Command line length        */
  962. #define HISTORY_MAX        100    /* History array length        */
  963.                     /* Space for full file name    */
  964. #define FFNAME_MAX        (PATH_MAX + NAME_MAX + 4)
  965. #define DOS_CMD_LINE_MAX    127    /* Max command line length    */
  966. #define ARRAY_SIZE(a)        ((sizeof (a)) / sizeof (a[0]))
  967.  
  968. #if (OS_TYPE == OS_DOS)
  969. #  define CMD_LINE_MAX        DOS_CMD_LINE_MAX
  970. #elif (OS_TYPE == OS_OS2)
  971. #  define CMD_LINE_MAX        32000    /* Max command line length    */
  972. #elif (OS_TYPE == OS_NT)
  973. #  define CMD_LINE_MAX        1024    /* Max command line length    */
  974. #endif
  975.  
  976.  
  977. #define SSAVE_IO_SIZE        4    /* Save IO array malloc inc    */
  978. #define LEN_DEVICE_NAME_HEADER    5    /* /dev/ string length        */
  979.  
  980. extern int    MaxNumberofFDs;        /* Max no of file descriptors    */
  981. #define    NUFILE            10    /* # of user-accessible files    */
  982. #define    FDBASE            10    /* First file usable by Shell    */
  983.  
  984. /*
  985.  * Some characters
  986.  */
  987.  
  988. #define CHAR_UNIX_DIRECTORY    '/'
  989. #define CHAR_NEW_LINE        '\n'
  990. #define CHAR_SINGLE_QUOTE    '\''
  991. #define CHAR_DOUBLE_QUOTE    '"'
  992. #define CHAR_BACKQUOTE        '`'
  993. #define CHAR_RETURN        '\r'
  994. #define CHAR_SPACE        ' '
  995. #define    CHAR_NOT        '^'
  996. #define    CHAR_TAB        '\t'
  997. #define    CHAR_BACKSPACE        '\b'
  998. #define CHAR_ESCAPE        0x1b
  999. #define    CHAR_XOR        '^'
  1000. #define    CHAR_BEGIN_LINE        '^'
  1001. #define CHAR_OPEN_PARATHENSIS    '('
  1002. #define CHAR_CLOSE_PARATHENSIS    ')'
  1003. #define CHAR_OPEN_BRACES    '{'
  1004. #define CHAR_CLOSE_BRACES    '}'
  1005. #define CHAR_OPEN_BRACKETS    '['
  1006. #define CHAR_CLOSE_BRACKETS    ']'
  1007. #define CHAR_TILDE        '~'
  1008. #define CHAR_PIPE        '|'
  1009. #define CHAR_HISTORY        '!'
  1010. #define CHAR_COMMENT        '#'
  1011. #define CHAR_MATCH_START    '#'
  1012. #define CHAR_VARIABLE        '$'
  1013. #define CHAR_END_LINE        '$'
  1014. #define CHAR_FORMAT        '%'
  1015. #define CHAR_JOBID        '%'
  1016. #define CHAR_MATCH_END        '%'
  1017. #define CHAR_ASYNC        '&'
  1018. #define CHAR_MATCH_ALL        '*'
  1019. #define CHAR_PLUS        '+'
  1020. #define CHAR_HYPHEN        '-'
  1021. #define CHAR_MATCH_RANGE    '-'
  1022. #define CHAR_CLOSE_FD        '-'
  1023. #define CHAR_SWITCH        '-'
  1024. #define CHAR_PERIOD        '.'
  1025. #define CHAR_COLON        ':'
  1026. #define CHAR_DRIVE        ':'
  1027. #define CHAR_SEPARATOR        ';'
  1028.  
  1029. #if (OS_TYPE == OS_UNIX)
  1030. #  define CHAR_PATH_SEPARATOR    ':'
  1031. #else
  1032. #  define CHAR_PATH_SEPARATOR    ';'
  1033. #endif
  1034.  
  1035. #define CHAR_INPUT        '<'
  1036. #define CHAR_ASSIGN        '='
  1037. #define CHAR_OUTPUT        '>'
  1038. #define CHAR_MATCH_ANY        '?'
  1039. #define CHAR_INDIRECT        '@'
  1040. #define CHAR_META        '\\'
  1041. #define CHAR_DOS_PATH        '\\'
  1042. #define CHAR_MAGIC        0x80
  1043.  
  1044. /*
  1045.  * fast character classes
  1046.  */
  1047.  
  1048. #define    C_ALPHA        0x001        /* a-z_A-Z            */
  1049. #define    C_DIGIT        0x002        /* 0-9                */
  1050. #define    C_LEX1        0x004        /* \0 \t\n|&;<>()        */
  1051. #define    C_VAR1        0x008        /* *@#!$-?            */
  1052. #define    C_SUBOP        0x010        /* "=-+?#%"            */
  1053. #define    C_IFS        0x020        /* $IFS                */
  1054. #define    C_WILD        0x040        /* Wildcards            */
  1055. #define    C_SEMICOLON    0x080        /* Semi-colon (;)        */
  1056.  
  1057. extern void        InitialiseCharacterTypes (void);
  1058. extern void        SetCharacterTypes (char *, int);
  1059. extern unsigned char    CharTypes [UCHAR_MAX + 1];
  1060.  
  1061. /*
  1062.  * Check for variable characters
  1063.  */
  1064.  
  1065. #define    IS_VariableFC(c)    (CharTypes[(c)] & C_ALPHA)
  1066. #define    IS_VariableSC(c)    (CharTypes[(c)] & (C_ALPHA | C_DIGIT))
  1067.  
  1068. #define    IS_Numeric(c)        (CharTypes[(c)] & C_DIGIT)
  1069. #define    IS_AlphaNumeric(c)    (CharTypes[(c)] & (C_ALPHA | C_DIGIT))
  1070. #define    IS_IFS(c)        (CharTypes[(c)] & C_IFS)
  1071. #define    IS_Lexical(c)        (CharTypes[(c)] & C_LEX1)
  1072. #define    IS_VarNumeric(c)    (CharTypes[(c)] & (C_DIGIT | C_VAR1))
  1073. #define    IS_VarOp(c)        (CharTypes[(c)] & C_SUBOP)
  1074. #define    IS_WildCard(c)        (CharTypes[(c)] & C_WILD)
  1075.  
  1076. extern char            *SkipToWhiteSpace (char *);
  1077.  
  1078. /*
  1079.  * File open modes
  1080.  */
  1081.                 /* Open in create mode            */
  1082. #define O_CMASK        (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY)
  1083.                 /* Open in create mode for a pipe    */
  1084. #define O_PMASK        (O_RDWR | O_CREAT | O_TRUNC | O_TEXT)
  1085.                 /* Open in create mode for swap file    */
  1086. #define O_SMASK        (O_RDWR | O_CREAT | O_TRUNC | O_BINARY)
  1087. #define O_SaMASK    (O_RDWR | O_BINARY)
  1088. #define O_RMASK        (O_RDONLY | O_NOINHERIT | O_TEXT)
  1089.  
  1090. /*
  1091.  * Path format conversion
  1092.  */
  1093.  
  1094. #define PATH_TO_UNIX(x)    ConvertPathToFormat ((x), CHAR_DOS_PATH,    \
  1095.                           CHAR_UNIX_DIRECTORY)
  1096. #define PATH_TO_DOS(x)    ConvertPathToFormat ((x), CHAR_UNIX_DIRECTORY,    \
  1097.                           CHAR_DOS_PATH)
  1098.  
  1099. #if (OS_TYPE == OS_UNIX)
  1100. #  define PATH_TO_UPPER_CASE(a)    
  1101. #  define PATH_TO_LOWER_CASE(a)
  1102. #  define IsHPFSFileSystem(a)    TRUE
  1103. #elif (OS_TYPE != OS_DOS)
  1104. #  define PATH_TO_UPPER_CASE(a)    {if (!IsHPFSFileSystem (a)) strupr (a); }
  1105. #  define PATH_TO_LOWER_CASE(a)    {if (!IsHPFSFileSystem (a)) strlwr (a); }
  1106. #else
  1107. #  define PATH_TO_UPPER_CASE(a)    { strupr (a); }
  1108. #  define PATH_TO_LOWER_CASE(a)    { strlwr (a); }
  1109. #  define IsHPFSFileSystem(a)    FALSE
  1110. #endif
  1111.  
  1112. /*
  1113.  * Drive support
  1114.  */
  1115.  
  1116. #if (OS_TYPE == OS_UNIX)
  1117. #  define IsDriveCharacter(a)        FALSE
  1118. #else
  1119. #  define IsDriveCharacter(a)        C2bool ((a) == CHAR_DRIVE)
  1120. #endif
  1121.  
  1122. #define IsPathCharacter(a)        C2bool ((a) == CHAR_UNIX_DIRECTORY)
  1123. #define FindLastPathCharacter(a)    strrchr (a, CHAR_UNIX_DIRECTORY)
  1124. #define FindPathCharacter(a)        strchr (a, CHAR_UNIX_DIRECTORY)
  1125.  
  1126. /*
  1127.  * shell components
  1128.  */
  1129.  
  1130. #define    NOBLOCK        ((C_Op *)NULL)
  1131. #define    NOWORD        ((char *)NULL)
  1132. #define    NOWORDS        ((char **)NULL)
  1133. #define    NOPIPE        (-1)
  1134.  
  1135. /*
  1136.  * Ignore Variables flags
  1137.  */
  1138.  
  1139. #define DISABLE_MAILCHECK    0x0001
  1140. #define DISABLE_OPTARG        0x0002
  1141. #define DISABLE_OPTIND        0x0004
  1142. #define DISABLE_SECONDS        0x0008
  1143. #define DISABLE_RANDOM        0x0010
  1144. #define DISABLE_LASTWORD    0x0020
  1145. #define DISABLE_LINECOUNT    0x0040
  1146. #define DISABLE_WINTITLE    0x0080
  1147.  
  1148. extern int    DisabledVariables;
  1149.  
  1150. /*
  1151.  * File Descriptor Types and Macros
  1152.  */
  1153.  
  1154. #define DESCRIPTOR_UNKNOWN    0x0000        /* Error - not known    */
  1155. #define DESCRIPTOR_PIPE        0x0001        /* Pipe            */
  1156. #define DESCRIPTOR_FILE        0x0002        /* File            */
  1157. #define DESCRIPTOR_DEVICE    0x0004        /* Device - tty        */
  1158. #define DESCRIPTOR_CONSOLE    0x0008        /* Console device    */
  1159.  
  1160. #define IS_Pipe(a)        (GetDescriptorType (a) & DESCRIPTOR_PIPE)
  1161. #define IS_File(a)        (GetDescriptorType (a) & DESCRIPTOR_FILE)
  1162. #define IS_TTY(a)        (GetDescriptorType (a) & \
  1163.                     (DESCRIPTOR_DEVICE | DESCRIPTOR_CONSOLE))
  1164. #define IS_Console(a)        (GetDescriptorType (a) & DESCRIPTOR_CONSOLE)
  1165.  
  1166. /*
  1167.  * Result from FindLocationOfExecutable
  1168.  */
  1169.  
  1170. #define EXTENSION_NOT_FOUND    0    /* Cannot find file        */
  1171. #define EXTENSION_EXECUTABLE    1    /* OS/2 or DOS .exe or .com    */
  1172. #define EXTENSION_BATCH        2    /* OS/2 or DOS .cmd or .bat    */
  1173. #define EXTENSION_SHELL_SCRIPT    3    /* Shell script            */
  1174. #define EXTENSION_OTHER        4    /* Other            */
  1175.  
  1176. /*
  1177.  * XString - Expandable strings
  1178.  *
  1179.  * XString functions:
  1180.  *
  1181.  * XFree   - Release the string
  1182.  * XStart  - Get start of string
  1183.  * XClose  - close a string
  1184.  * XCreate - Create a string
  1185.  * XCheck  - Check for overflow
  1186.  */
  1187.  
  1188. typedef struct XString {
  1189.     unsigned char    *SStart;    /* End of string        */
  1190.     unsigned char    *SEnd;        /* Beginning of string        */
  1191.     size_t        SLength;    /* length            */
  1192. } XString;
  1193.  
  1194. #define    XFree(xs)        ReleaseMemoryCell ((void*)(xs).SStart)
  1195. #define    XStart(xs)        ((xs).SStart)
  1196. #define    XCurrentOffset(xs, xp)    (xp - (xs).SStart)
  1197. #define    XResetOffset(xs, n)    ((xs).SStart + (n))
  1198.  
  1199. extern void             XCheck (XString *, unsigned char **);
  1200. extern char            *XClose (XString *, unsigned char *);
  1201. extern char            *XCreate (XString *, size_t);
  1202.  
  1203. /*
  1204.  * Description of a command or an operation on commands.
  1205.  * Might eventually use a union.
  1206.  */
  1207.  
  1208. typedef struct op {
  1209.     int            type;        /* operation type, see below    */
  1210.     char        **args;        /* arguments to a command    */
  1211.     char        **vars;        /* variable assignments        */
  1212.     struct ioword    **ioact;    /* IO actions (eg, < > >>)    */
  1213.     struct op        *left;
  1214.     struct op        *right;
  1215.     char        *str;        /* identifier for case and for    */
  1216. } C_Op;
  1217.  
  1218. /*
  1219.  * C_Op.type values
  1220.  */
  1221.  
  1222. #define    TEOF        0
  1223. #define    TCOM        1    /* command                */
  1224. #define    TPAREN        2    /* (c-list)                */
  1225. #define    TPIPE        3    /* a | b                */
  1226. #define    TLIST        4    /* a [&;] b                */
  1227. #define    TOR        5    /* ||                    */
  1228. #define    TAND        6    /* &&                    */
  1229. #define    TFOR        7    /* FOR                    */
  1230. #define    TCOPROCESS    8    /* coprocess                */
  1231. #define    TCASE        9    /* CASE                    */
  1232. #define    TIF        10    /* IF                    */
  1233. #define    TWHILE        11    /* WHILE                */
  1234. #define    TUNTIL        12    /* UNTIL                */
  1235. #define    TELIF        13    /* ELSE IF                */
  1236. #define    TPAT        14    /* pattern in case            */
  1237. #define    TBRACE        15    /* {c-list}                */
  1238. #define    TASYNC        16    /* c &                    */
  1239. #define    TFUNC        17    /* c () {c-list}            */
  1240. #define    TSELECT        18    /* SELECT                */
  1241. #define    TTIME        19    /* time pipeline            */
  1242.  
  1243. /*
  1244.  * Prefix codes for words in command tree
  1245.  */
  1246.  
  1247. #define    WORD_EOS    0    /* end of string            */
  1248. #define    WORD_CHAR    1    /* unquoted character            */
  1249. #define    WORD_QCHAR    2    /* quoted character            */
  1250. #define    WORD_QTCHAR    3    /* temporary quoted character        */
  1251. #define    WORD_COMSUB    4    /* $() substitution (0 terminated)    */
  1252. #define    WORD_OQUOTE    5    /* opening '                */
  1253. #define    WORD_CQUOTE    6    /* closing '                */
  1254. #define    WORD_ODQUOTE    7    /* opening "                 */
  1255. #define    WORD_CDQUOTE    8    /* closing "                */
  1256. #define    WORD_OSUBST    9    /* opening ${ substitution        */
  1257. #define    WORD_CSUBST    10    /* closing } of above            */
  1258. #define    WORD_OMATHS    11    /* opening $(()) substitution (0 term)    */
  1259. #define WORD_OARRAY    12    /* opening ${name[ of array        */
  1260. #define WORD_CARRAY    13    /* closing ] for above            */
  1261.  
  1262. /*
  1263.  * Syntax and Lexical Analysis
  1264.  *
  1265.  * Lexical tokens
  1266.  */
  1267.  
  1268. #define PARSE_WORD        256
  1269. #define PARSE_LOGICAL_AND    257    /* && */
  1270. #define PARSE_LOGICAL_OR    258    /* || */
  1271. #define PARSE_BREAK        259
  1272. #define PARSE_IF        260
  1273. #define PARSE_THEN        261
  1274. #define PARSE_ELSE        262
  1275. #define PARSE_ELIF        263
  1276. #define PARSE_FI        264
  1277. #define PARSE_CASE        265
  1278. #define PARSE_ESAC        266
  1279. #define PARSE_FOR        267
  1280. #define PARSE_WHILE        268
  1281. #define PARSE_UNTIL        269
  1282. #define PARSE_DO        270
  1283. #define PARSE_DONE        271
  1284. #define PARSE_IN        272
  1285. #define PARSE_SELECT        273
  1286. #define PARSE_FUNCTION        274
  1287. #define    PARSE_TIME        275
  1288. #define    PARSE_REDIR        276        /* >, <, etc */
  1289. #define    PARSE_MPAREN        277        /* () */
  1290. #define    PARSE_MDPAREN        278        /* (( )) */
  1291. #define    PARSE_TEST        279        /* [[ ]] */
  1292. #define    PARSE_COPROCESS        280        /* |& */
  1293. #define YYERRCODE        300
  1294.  
  1295. /*
  1296.  * Lexical token value
  1297.  */
  1298.  
  1299. typedef union {
  1300.     int            i;            /* Integer        */
  1301.     char        *cp;            /* String        */
  1302.     char        **wp;            /* List            */
  1303.     struct op        *o;            /* Command tree        */
  1304.     struct ioword    *iop;            /* IO action        */
  1305. } YYSTYPE;
  1306.  
  1307. /*
  1308.  * flags to ScanNextToken
  1309.  */
  1310.  
  1311. #define    ALLOW_CONTINUATION    0x0001    /* skip new lines to complete    */
  1312.                     /* command            */
  1313. #define    ONEWORD            0x0002    /* single word for substitute()    */
  1314. #define    ALLOW_ALIAS        0x0004    /* recognize alias        */
  1315. #define    ALLOW_KEYWORD        0x0008    /* recognize keywords        */
  1316. #define    MATHS_EXPRESSION    0x0010    /* get expression inside (( ))    */
  1317. #define    TEST_EXPRESSION        0x0020    /* get expression inside [[ ]]    */
  1318.  
  1319.  
  1320. #define    IDENT            64    /* Max size of an Identifier    */
  1321. extern char            CurrentLexIdentifier [IDENT+1];
  1322.  
  1323. /*
  1324.  * Input descriptor for yylex
  1325.  */
  1326.  
  1327. typedef struct source {
  1328.     char        *str;        /* input pointe            */
  1329.     int            type;        /* input type            */
  1330.     union {
  1331.     char            **strv;        /* string []        */
  1332.     FILE            *file;        /* file            */
  1333.     struct AliasList    *Calias;    /* alias        */
  1334.     }            u;
  1335.  
  1336.     int            line;        /* line number            */
  1337.     char        *file;        /* input file name        */
  1338.     bool        echo;        /* echo input to shlout        */
  1339.     struct source    *next;        /* stacked source        */
  1340. } Source;
  1341.  
  1342. /* Source.type values */
  1343.  
  1344. #define    SEOF        0    /* input EOF                */
  1345. #define    STTY        1    /* terminal input            */
  1346. #define    SFILE        2    /* file input                */
  1347. #define    SWSTR        3    /* string without \n            */
  1348. #define    SSTRING        4    /* string                */
  1349. #define    SWORDS        5    /* string[]                */
  1350. #define    SALIAS        6    /* alias expansion            */
  1351. #define    SWORDSEP    8    /* string[] seperator            */
  1352.  
  1353. extern Source        *pushs (int);         /* push Source        */
  1354. extern C_Op        *compile (Source *s);    /* compile tree        */
  1355.  
  1356.  
  1357. extern Source        *source;    /* yyparse/yylex source        */
  1358. extern YYSTYPE        yylval;        /* result from yylex        */
  1359. extern int        yynerrs;
  1360.  
  1361. /* Built in Command list */
  1362.  
  1363. struct    builtin {
  1364.     char    *command;
  1365.     int        (*fn)(int, char **);
  1366.     int        mode;
  1367. };
  1368.  
  1369. extern int    doexec (C_Op *);    /* Exec function a cheat    */
  1370.  
  1371. /*
  1372.  * Valid values of mode
  1373.  */
  1374.  
  1375. #define BLT_ALWAYS    0x0001    /* Always use builtin version        */
  1376. #define BLT_CURRENT    0x0002    /* Currently use builtin version    */
  1377. #define BLT_NOGLOB    0x0004    /* No globbing for this internal    */
  1378. #define BLT_CENVIRON    0x0008    /* Don't create a new environment    */
  1379. #define BLT_NOWORDS    0x0010    /* Don't split words for this internal    */
  1380. #define BLT_SKIPGLOB    (BLT_CURRENT | BLT_NOGLOB)
  1381. #define BLT_SKIPENVIR    (BLT_CURRENT | BLT_CENVIRON)
  1382.  
  1383. /*
  1384.  * actions determining the environment of a process
  1385.  */
  1386.  
  1387. #define    EXEC_WITHOUT_FORK    0x0001    /* execute without forking    */
  1388. #define    EXEC_FUNCTION        0x0002    /* execute a function        */
  1389.  
  1390. #if (OS_TYPE != OS_DOS)
  1391. #  define EXEC_SPAWN_NOWAIT    0x0004    /* execute a non-wait        */
  1392. #  define EXEC_SPAWN_DETACH    0x0008    /* execute a detach        */
  1393. #  define EXEC_SPAWN_IGNOREWAIT    0x0010    /* Pipe processing        */
  1394. #endif
  1395.  
  1396. #define EXEC_PIPE_IN        0x0020    /* On pipe            */
  1397. #define EXEC_PIPE_SUBS        0x0040    /* Second command        */
  1398. #define EXEC_WINDOWS        0x0080    /* Start Windows app        */
  1399.  
  1400. /* MSDOS Memory Control Block chain structure */
  1401.  
  1402. #ifdef OS_SWAPPING
  1403. #  pragma pack (1)
  1404. struct MCB_list    {
  1405.     char        MCB_type;    /* M or Z            */
  1406.     unsigned int    MCB_pid;    /* Process ID            */
  1407.     unsigned int    MCB_len;    /* MCB length            */
  1408. };
  1409. #  pragma pack ()
  1410.  
  1411. #  define MCB_CON    'M'        /* More MCB's            */
  1412. #  define MCB_END    'Z'        /* Last MCB's            */
  1413. #endif
  1414.  
  1415. /* Externs for Swapper assembler function */
  1416.  
  1417. #ifdef OS_SWAPPING
  1418. extern char far        cmd_line[];    /* Command line            */
  1419. extern char far        path_line[];    /* Process path            */
  1420. extern unsigned int far    SW_intr;    /* interrupt pending        */
  1421. #else
  1422. extern unsigned int     SW_intr;    /* interrupt pending        */
  1423. extern bool        IgnoreInterrupts;/* Ignore interrupts flag    */
  1424. #endif
  1425.  
  1426. extern int        LastNumberBase;    /* Last base entered        */
  1427.  
  1428. #ifdef OS_SWAPPING
  1429. extern unsigned int far    SW_Blocks;    /* Number of blocks to read    */
  1430. extern unsigned int far    SW_SBlocks;    /* Short Number of blocks to    */
  1431.                     /* read                */
  1432. extern unsigned int far    SW_MinESpace;    /* Minimum environment space    */
  1433. extern int far        SW_fp;        /* File or EMS Handler        */
  1434. extern int far        SW_Pwrite;    /* Partial write to disk?    */
  1435. extern unsigned long far    SW_EMstart;/* Start addr of extend mem    */
  1436. extern unsigned int far    SW_Mode;    /* Type of swapping to do    */
  1437.                     /* 1 - disk            */
  1438.                     /* 2 - Extended    memory        */
  1439.                     /* 3 - EMS Driver        */
  1440.                     /* 4 - XMS Driver        */
  1441. extern unsigned int far    SW_EMSFrame;    /* EMS Frame segment        */
  1442.  
  1443. extern unsigned int far    etext;        /* End of text segment        */
  1444. extern int        Swap_Mode;    /* Swapping mode        */
  1445.  
  1446. /* If you change these values, change sh7, swap_device as well */
  1447.  
  1448. #  define SWAP_OFF    0x0000        /* No swapping            */
  1449. #  define SWAP_DISK    0x0001        /* Disk only            */
  1450. #  define SWAP_EXTEND    0x0002        /* Extended memory        */
  1451. #  define SWAP_EXPAND    0x0004        /* Expanded memory        */
  1452. #endif
  1453.  
  1454. /*
  1455.  * Convert to bool
  1456.  */
  1457.  
  1458. #define C2bool(c)    (bool)((c) ? TRUE : FALSE)
  1459.  
  1460. /*
  1461.  * flags to control evaluation of words
  1462.  */
  1463.  
  1464. #define    EXPAND_SPLITIFS    0x01    /* Perform blank interpretation        */
  1465. #define    EXPAND_GLOBBING    0x02    /* Do globbing on name            */
  1466. #define EXPAND_PATTERN    0x04    /* quote *?[                */
  1467. #define    EXPAND_TILDE    0x10    /* expand ~                 */
  1468. #define    EXPAND_CONVERT    0x20    /* Convert - and / to DOS format    */
  1469. #define    EXPAND_NOALTS    0x40    /* No alternations            */
  1470.  
  1471. /*
  1472.  * Hard error handler
  1473.  */
  1474.  
  1475. #if (OS_TYPE == OS_OS2)
  1476. #  if (OS_SIZE == OS_32)
  1477. #    define DISABLE_HARD_ERRORS        DosError (FERR_DISABLEHARDERR)
  1478. #    define ENABLE_HARD_ERRORS        DosError (FERR_ENABLEHARDERR)
  1479. #  else
  1480. #    define DISABLE_HARD_ERRORS        DosError (HARDERROR_DISABLE)
  1481. #    define ENABLE_HARD_ERRORS        DosError (HARDERROR_ENABLE)
  1482. #  endif
  1483.  
  1484. #elif (OS_TYPE == OS_NT)
  1485. #  define DISABLE_HARD_ERRORS        SetErrorMode (SEM_FAILCRITICALERRORS | \
  1486.                               SEM_NOOPENFILEERRORBOX)
  1487. #  define ENABLE_HARD_ERRORS        SetErrorMode (0)
  1488.  
  1489. #elif (OS_TYPE == OS_DOS)
  1490. #  if (OS_SIZE == OS_32)
  1491. extern bool    IgnoreHardErrors;
  1492. #    define DISABLE_HARD_ERRORS        IgnoreHardErrors = TRUE;
  1493. #    define ENABLE_HARD_ERRORS        IgnoreHardErrors = FALSE;
  1494. #  else
  1495. #    define DISABLE_HARD_ERRORS
  1496. #    define ENABLE_HARD_ERRORS
  1497. #  endif
  1498.  
  1499. #elif (OS_TYPE == OS_UNIX)
  1500. #  define DISABLE_HARD_ERRORS
  1501. #  define ENABLE_HARD_ERRORS
  1502. #endif
  1503.  
  1504. /*
  1505.  * General variables
  1506.  */
  1507.  
  1508. extern char        **ParameterArray;/* $<numeric> values        */
  1509. extern int        ParameterCount;    /* $<numeric> count        */
  1510. extern int        ExitStatus;
  1511. extern bool        ExpansionErrorDetected;
  1512. extern bool        InteractiveFlag;/* interactive            */
  1513. extern bool        ProcessingEXECCommand;
  1514. extern int        AllowMultipleLines;    /* Allow continuation    */
  1515. extern int        Current_Event;    /* Current history event    */
  1516. extern bool        ChangeInitLoad;    /* Change load .ini point.    */
  1517.  
  1518. /*
  1519.  * Break/Continue (in for and while), Return and Exit handler
  1520.  */
  1521.  
  1522. typedef struct brkcon {
  1523.     jmp_buf        CurrentReturnPoint;
  1524.     struct brkcon    *NextExitLevel;
  1525. } Break_C;
  1526.                 /* Values returned by longjmp        */
  1527. #define BC_LOAD        0    /* Load condition            */
  1528. #define BC_BREAK    1    /* Break condition            */
  1529. #define BC_CONTINUE    2    /* Continue condition            */
  1530.  
  1531. extern Break_C    *Break_List;    /* Break list for FOR/WHILE        */
  1532. extern Break_C    *Return_List;    /* Return list for RETURN        */
  1533. extern Break_C    *SShell_List;    /* SubShell list for EXIT        */
  1534. extern bool    RestrictedShellFlag;    /* Read only shell        */
  1535. extern bool    HistoryEnabled;
  1536.  
  1537. /*
  1538.  * Word List structure
  1539.  */
  1540.  
  1541. typedef struct wdblock {
  1542.     short    w_bsize;
  1543.     short    w_nword;
  1544.     char    *w_words[1];
  1545. } Word_B;
  1546.  
  1547. /*
  1548.  * Save Standard Input/Output/Error structure
  1549.  */
  1550.  
  1551. typedef struct save_io {
  1552.     int        depth;            /* Execute recursive depth    */
  1553.     int        fp[STDERR_FILENO + 1];    /* File handlers        */
  1554. } Save_IO;
  1555.  
  1556. extern Save_IO    *SSave_IO;        /* Save IO array        */
  1557. extern int    NSave_IO_E;        /* Number of entries        */
  1558. extern int    MSave_IO_E;        /* Max Number of entries    */
  1559.  
  1560. /*
  1561.  * Function tree processing
  1562.  */
  1563.  
  1564. typedef struct FunctionList {
  1565.     C_Op        *tree;        /* The tree itself        */
  1566.     bool        Traced;        /* Traced flag            */
  1567. } FunctionList;
  1568.  
  1569. extern void        *FunctionTree;    /* Function Tree root        */
  1570. extern FunctionList    *CurrentFunction;
  1571.  
  1572. /*
  1573.  * Alias processing
  1574.  */
  1575.  
  1576. typedef struct AliasList {
  1577.     char        *name;        /* The alias name        */
  1578.     char        *value;        /* The alias            */
  1579.     int            AFlags;        /* Alias flags            */
  1580. } AliasList;
  1581.  
  1582. extern void        *AliasTree;    /* Alias Tree root        */
  1583.  
  1584. #define ALIAS_TRACKED        0x0001    /* Tracked alias        */
  1585. #define ALIAS_EXPANDING        0x0002    /* Alias being expanded        */
  1586. #define MAX_RECURSIVEALIASES    20    /* Max depth of recursive alias    */
  1587.  
  1588. /*
  1589.  * Job Processing
  1590.  */
  1591.  
  1592. #if (OS_TYPE != OS_DOS)
  1593.  
  1594. #  if (OS_TYPE == OS_NT)
  1595. typedef DWORD        PID;        /* Set up PID definition for NT */
  1596. #  endif
  1597.  
  1598. typedef struct JobList {
  1599.     int            Number;        /* Current number        */
  1600.     PID            pid;        /* Process ID             */
  1601.     unsigned short    SessionId;    /* Session ID            */
  1602.     char        *Command;    /* Program            */
  1603. } JobList;
  1604.  
  1605. extern void        *JobTree;    /* Job Tree root        */
  1606. extern bool        ExitWithJobsActive;    /* Exit flag        */
  1607. extern int        CurrentJob;        /* No current        */
  1608. extern int        PreviousJob;        /* Previous Job        */
  1609.  
  1610. /*
  1611.  * Session Info
  1612.  */
  1613.  
  1614. extern char        *SessionEndQName;    /* Queue name        */
  1615.  
  1616. /*
  1617.  * Special flag for EMX parameters
  1618.  */
  1619.  
  1620. extern bool        EMXStyleParameters;
  1621. #endif
  1622.  
  1623. /*
  1624.  * redirection
  1625.  */
  1626.  
  1627. typedef struct ioword {
  1628.     short    io_unit;    /* unit affected            */
  1629.     short    io_flag;    /* action (below)            */
  1630.     char    *io_name;    /* file name                */
  1631. } IO_Actions;
  1632.  
  1633. #define    IOTYPE        0x000f    /* type: bits 0:3            */
  1634. #define    IOREAD        0x0001    /* <                    */
  1635. #define    IOWRITE        0x0002    /* >                    */
  1636. #define    IORDWR        0x0003    /* <>                    */
  1637. #define    IOHERE        0x0004    /* << (here file)            */
  1638. #define    IOCAT        0x0005    /* >>                    */
  1639. #define    IODUP        0x0006    /* >&digit                */
  1640. #define    IOCLOSE        0x0007    /* >&-                    */
  1641. #define    IOEVAL         0x0010    /* Expand in <<                */
  1642. #define    IOSKIP        0x0020    /* <<- (here file            */
  1643. #define    IOCLOBBER    0x0040    /* >| overwrite noclobber        */
  1644. #define IOFUNCTION    0x0080    /* The Here document name is inside a    */
  1645.                 /* function - don't delete it        */
  1646.  
  1647. /*
  1648.  * parsing & execution environment
  1649.  *
  1650.  * For some reason, MSC (and IBM C Set/2), don't like taking addresses
  1651.  * of jmp_buf's, so this macro set removes the errors
  1652.  */
  1653.  
  1654. #if defined (__TURBOC__) || defined (__WATCOMC__)
  1655. #  define ErrorPoint        jmp_buf *
  1656. #  define SetErrorPoint(a)    setjmp (*(e.ErrorReturnPoint = &(a)))
  1657. #  define ExitErrorPoint(a)    longjmp (*(e.ErrorReturnPoint), a)
  1658. #else
  1659. #  define ErrorPoint        int *
  1660. #  define SetErrorPoint(a)    setjmp (e.ErrorReturnPoint = a)
  1661. #  define ExitErrorPoint(a)    longjmp (e.ErrorReturnPoint, a)
  1662. #endif
  1663.  
  1664. #define TERMINATE_POINT_SET    0    /* Error point set        */
  1665. #define TERMINATE_COMMAND    1    /* Exit Error point for command    */
  1666. #define TERMINATE_SHELL        2    /* Exit Error point for shell    */
  1667.  
  1668.  
  1669. /* The environment structure itself */
  1670.  
  1671. typedef struct env {
  1672.     ErrorPoint        ErrorReturnPoint;
  1673.     unsigned long    IOMap;        /* File Descriptors open in     */
  1674.                     /* this environment        */
  1675.     char        *line;        /* Current input line        */
  1676.                     /* Previous environment        */
  1677.     struct env        *PreviousEnvironment;
  1678.     Word_B        *OpenStreams;
  1679. } ShellFileEnvironment;
  1680.  
  1681. extern ShellFileEnvironment    e;
  1682.  
  1683. /*
  1684.  * Switches/flags
  1685.  */
  1686.  
  1687. #define FL_TEST(x)    (flags & (1L << ((x) - 'a')))
  1688. #define FL_SET(x)    flags |= (1L << ((x) - 'a'))
  1689. #define FL_CLEAR(x)    flags &= (~(1L << ((x) - 'a')))
  1690.  
  1691. extern long    flags;
  1692.  
  1693. /*
  1694.  * Switch values
  1695.  */
  1696.  
  1697. #define FLAG_ALL_EXPORT        'a'    /* Set all env vars to exported    */
  1698. #define FLAG_EXECUTE_STRING    'c'    /* Command from string        */
  1699. #define FLAG_EXIT_ON_ERROR    'e'    /* Quit on error        */
  1700. #define FLAG_DISABLE_GLOB    'f'    /* Disable file name expansion    */
  1701. #define FLAG_TRACK_ALL        'h'    /* Track all aliases        */
  1702. #define FLAG_INTERACTIVE    'i'    /* Interactive shell        */
  1703. #define FLAG_ALL_KEYWORDS    'k'    /* Look for name=value everywhere */
  1704. #define FLAG_SEPARATE_GROUP    'm'    /* Separate process group    */
  1705. #define FLAG_NO_EXECUTE        'n'    /* No execution            */
  1706. #define FLAG_READONLY_SHELL    'r'    /* Read only shell        */
  1707. #define FLAG_POSITION        's'    /* Read from standard input    */
  1708. #define FLAG_ONE_COMMAND    't'    /* exit after exec'ing 1 cmd    */
  1709. #define FLAG_UNSET_ERROR    'u'     /* Abort if env var not set    */
  1710. #define FLAG_ECHO_INPUT        'v'    /* Echo as read            */
  1711. #define FLAG_WARNING        'w'    /* No Warning messages        */
  1712. #define FLAG_PRINT_EXECUTE    'x'    /* Trace            */
  1713.  
  1714. /*
  1715.  * Global flags set by set -o which do not have single letter equivalents
  1716.  */
  1717.  
  1718. extern unsigned int        ShellGlobalFlags;
  1719.  
  1720. #define FLAGS_NONE        0x0000
  1721. #define FLAGS_IGNOREEOF        0x0001    /* Ignore EOF            */
  1722. #define FLAGS_MARKDIRECTORY    0x0002    /* Mark directories with /    */
  1723. #define FLAGS_NOCLOBER        0x0004    /* No delete on existing files    */
  1724. #define FLAGS_FUNCTION        0x0008    /* Special value used in    */
  1725.                     /* CreateGlobalVariableList.    */
  1726.                     /* Indicates a function caused  */
  1727.                     /* CGVL to be called. Not used    */
  1728.                     /* otherwise            */
  1729. #define FLAGS_REALPIPES        0x0010    /* Use Real pipes under OS/2    */
  1730. #define FLAGS_ALTERNATION    0x0020    /* Allow alternations        */
  1731.  
  1732. #define FLAGS_EDITORS        0x01c0    /* Any of Emacs, Gmacs, or Vi    */
  1733. #define FLAGS_NOCASE        0x0200    /* Ignore case            */
  1734. #define FLAGS_MSDOS_FORMAT    0x0400    /* MSDOS format environment    */
  1735. #define FLAGS_VERIFY_SWITCH    0x0800    /* Change verify status        */
  1736.  
  1737. #if (OS_TYPE == OS_DOS)
  1738. #define FLAGS_BREAK_SWITCH    0x1000    /* Change break status        */
  1739. #define FLAGS_SET_OS2        0x2000    /* Set OS to OS2        */
  1740. #define FLAGS_SET_NT        0x4000    /* Set OS to NT            */
  1741. #endif
  1742.  
  1743. #define FLAGS_VI        0x0040    /* Vi mode            */
  1744. #define FLAGS_EMACS        0x0080    /* Emacs mode            */
  1745. #define FLAGS_GMACS        0x0100    /* Gmacs mode            */
  1746.  
  1747. extern char    null[];        /* null value for variable        */
  1748. extern int    InterruptTrapPending;    /* trap pending            */
  1749. extern int    Execute_stack_depth;    /* execute function recursion    */
  1750.                     /* depth            */
  1751.  
  1752. /*
  1753.  * Mode values for new GeneralPatternMatch
  1754.  */
  1755.  
  1756. #define GM_ALL        0        /* Match full string        */
  1757. #define GM_SHORTEST    1        /* Shortest prefix/suffix    */
  1758. #define GM_LONGEST    2        /* Longest prefix/suffix    */
  1759.  
  1760. /*
  1761.  * Variable list
  1762.  */
  1763.  
  1764. typedef struct var {
  1765.     char        *name;        /* Name                */
  1766.     char        *value;        /* Value            */
  1767.     int            index;        /* Array index            */
  1768.     unsigned long    nvalue;        /* Numeric value        */
  1769.     unsigned int    base;        /* Numeric base            */
  1770.     unsigned int    width;        /* Field width            */
  1771.     unsigned int    status;        /* Type, see below        */
  1772. } VariableList;
  1773.  
  1774. #define    STATUS_READONLY        0x0001    /* variable is read-only    */
  1775. #define    STATUS_EXPORT        0x0002    /* variable is to be exported    */
  1776. #define STATUS_CANNOT_UNSET    0x0008    /* PATH Value - no unset    */
  1777. #define STATUS_CONVERT_MSDOS    0x0010    /* Convert to MSDOS format    */
  1778. #define STATUS_LEFT_JUSTIFY    0x0020    /* Left Justify            */
  1779. #define STATUS_RIGHT_JUSTIFY    0x0040    /* Right Justify        */
  1780. #define STATUS_ZERO_FILL    0x0080    /* Zero fill            */
  1781. #define STATUS_LOWER_CASE    0x0100    /* Convert to lower case    */
  1782. #define STATUS_UPPER_CASE    0x0200    /* Convert to upper case    */
  1783. #define STATUS_INTEGER        0x0400    /* Contains integer value    */
  1784. #define STATUS_TAGGED        0x0800    /* User tagged            */
  1785. #define STATUS_LOCAL        0x1000    /* Local variable in function    */
  1786. #define STATUS_GLOBAL        0x2000    /* Global variable        */
  1787. #define STATUS_NOEXISTANT    0x8000    /* Does not exist        */
  1788.  
  1789. extern void        *VariableTree;        /* Variable dictionary    */
  1790. extern VariableList    *CurrentDirectory;    /* Current directory    */
  1791. extern char    PS1[];            /* Prompt 1            */
  1792. extern char    PS2[];            /* Prompt 2            */
  1793. extern char    PS3[];            /* Prompt 3            */
  1794. extern char    PS4[];            /* Prompt 4            */
  1795. extern char    IFS[];            /* Interfield separators    */
  1796. extern char    *LastUserPrompt;    /* Last prompt output        */
  1797. extern char    *LastUserPrompt1;    /* Alternate prompt output    */
  1798. extern char    PathLiteral[];        /* PATH Variable        */
  1799. extern char    CDPathLiteral[];    /* CDPATH Variable        */
  1800. extern char    CurrentDirLiteral[];    /* Current Directory        */
  1801. extern char    ParentDirLiteral[];    /* Parent Directory        */
  1802. extern char    PathExtsLiteral[];    /* PATHEXTS Variable        */
  1803. extern char    HomeVariableName[];    /* Home Variable        */
  1804. extern char    ShellVariableName[];    /* Shell Variable        */
  1805. extern char    *ParameterCountVariable;/* Parameter Count Variable (#)    */
  1806. extern char    *ShellOptionsVariable;    /* Shell Options Variable (-)    */
  1807. extern char    StatusVariable[];    /* Status variable (?)        */
  1808. extern char    *ComspecVariable;    /* COMSPEC string        */
  1809. extern char    SecondsVariable[];    /* Seconds string        */
  1810. extern char    RandomVariable[];    /* Random string        */
  1811. extern char    LineCountVariable[];    /* LINENO string        */
  1812. extern char    *RootDirectory;        /* Root directory        */
  1813.  
  1814.  
  1815. #if (OS_TYPE != OS_DOS)
  1816. extern char    WinTitleVariable[];    /* WINTITLE string        */
  1817. #endif
  1818.  
  1819. extern char    *OldPWDVariable;    /* OLDPWD string        */
  1820. extern char    *PWDVariable;        /* PWD string            */
  1821. extern char    *ENVVariable;        /* ENV string            */
  1822. extern char    BATExtension[];        /* .bat string            */
  1823. extern char    SHELLExtension[];    /* .sh string            */
  1824. extern char    KSHELLExtension[];    /* .ksh string            */
  1825. extern char    EXEExtension[];        /* .exe string            */
  1826. extern char    COMExtension[];        /* .com string            */
  1827. extern char    HistoryFileVariable[];    /* HISTFILE string        */
  1828. extern char    HistorySizeVariable[];    /* HISTSIZE string        */
  1829. extern bool    UseConsoleBuffer;    /* Flag from dofc to        */
  1830.                     /* GetConsoleInput        */
  1831. extern char    *NotFound;        /* Not found message        */
  1832. extern char    *BasicErrorMessage;    /* Basic error message        */
  1833. extern char    *DirectorySeparator;    /* Directory separator        */
  1834. extern char    *DeviceNameHeader;    /* /dev/            */
  1835. extern char    LastWordVariable[];    /* Last word of command variable*/
  1836. extern char    OptArgVariable[];    /* OPTARG            */
  1837. extern char    OptIndVariable[];    /* OPTIND            */
  1838. extern char    MailCheckVariable[];    /* MAILCHECK            */
  1839. extern char    FCEditVariable[];    /* FCEDIT            */
  1840. extern char    EditorVariable[];    /* EDITOR            */
  1841. extern char    VisualVariable[];    /* VISUAL            */
  1842. extern char    Trap_DEBUG[];        /* DEBUG trap variable        */
  1843. extern char    Trap_ERR[];        /* ERR trap variable        */
  1844. extern char    ConsoleLineBuffer[];    /* Console line buffer        */
  1845. extern char    LIT_dos[];        /* dos Literal            */
  1846. extern char    *LIT_NewLine;        /* NewLine Literal        */
  1847. extern char    *LIT_BadID;        /* Bad Identifier literal    */
  1848. extern char    *LIT_OSname;        /* OS name            */
  1849. extern char    LIT_export[];        /* export literal        */
  1850. extern char    LIT_history[];        /* history literal        */
  1851. extern char    LIT_REPLY[];        /* Reply literal        */
  1852. extern char    LIT_exit[];        /* Exit literal            */
  1853. extern char    LIT_exec[];        /* Exec literal            */
  1854. extern char    LIT_done[];        /* done literal            */
  1855. extern char    LIT_LINES[];        /* LINES literal        */
  1856. extern char    LIT_COLUMNS[];        /* COLUMNS literal        */
  1857. extern char    *LIT_2Strings;        /* 2 String concat        */
  1858. extern char    *LIT_3Strings;        /* 3 string concat        */
  1859. extern char    *ListVarFormat;        /* List variable format        */
  1860. extern char    *Outofmemory1;        /* Out of memory string        */
  1861. extern char    *LIT_Emsg;        /* Error message format        */
  1862. extern char    *LIT_SyntaxError;    /* Syntax error            */
  1863. extern char     *LIT_BadArray;        /* Bad Array value        */
  1864. extern char    *LIT_ArrayRange;    /* subscript out of range    */
  1865. extern char    *LIT_BNumber;        /* [%d]                */
  1866. extern char    *LIT_Invalidfunction;    /* Invalid function name    */
  1867. extern char    *LIT_AllowTTY;        /* Allow Psuedo TTYs        */
  1868. extern char    *LIT_IsReadonly;    /* is readonly            */
  1869. extern char    LIT_Test[];        /* Test function        */
  1870. extern char    *sOpenReadMode;        /* Open file in read mode    */
  1871. extern char    *sOpenWriteMode;    /* Open file in write mode    */
  1872. extern char    *sOpenAppendMode;    /* Open file in append mode    */
  1873. extern char    *sOpenWriteBinaryMode;    /* Open file in append mode    */
  1874. extern int    MaximumColumns;        /* Max columns            */
  1875. extern int    MaximumLines;        /* Max Lines            */
  1876. extern int    StartCursorPosition;    /* Start cursor position    */
  1877.  
  1878. #if (OS_TYPE == OS_OS2) || (OS_TYPE == OS_NT)
  1879. extern void    SetWindowName (char *);    /* Set the Window Name        */
  1880. #else
  1881. #  define SetWindowName(a)
  1882. #endif
  1883.  
  1884. /*
  1885.  * Note the the following global structure is used to pass session
  1886.  * information around.  If the value of the Environment field is
  1887.  * (char *)NULL, then the parent environment is used.  If the value is
  1888.  * (char *)1, then the environment is built from the current exported
  1889.  * environment.  Otherwise the value of Environment is used as the
  1890.  * environment
  1891.  */
  1892.  
  1893. #if (OS_TYPE == OS_OS2)
  1894. extern STARTDATA *SessionControlBlock;        /* Start a session info    */
  1895. extern STARTDATA PM_SessionControlBlock;    /* PM session defaults    */
  1896. extern STARTDATA DOS_SessionControlBlock;    /* DOS session defaults    */
  1897. #endif
  1898.  
  1899. /*
  1900.  * SubShell Save Structure
  1901.  */
  1902.  
  1903. typedef struct subshell {
  1904.     int            depth;        /* Sub_Shell Depth        */
  1905.     unsigned int    GFlags;        /* Global flags            */
  1906.     long        Eflags;        /* single letter flags        */
  1907.     void        *OldVariableTree;    /* Header start        */
  1908. } S_SubShell;
  1909.  
  1910. extern S_SubShell    *SubShells;    /* Save Vars array        */
  1911. extern int        NSubShells;    /* Number of entries        */
  1912. extern int        MSubShells;    /* Max Number of entries    */
  1913.  
  1914.  
  1915. /*
  1916.  * Extract field from a line
  1917.  */
  1918.  
  1919. typedef struct Fields {
  1920.     FILE    *FP;            /* File handler            */
  1921.     char    *Line;            /* Line buffer            */
  1922.     int        LineLength;        /* Line Length            */
  1923.     Word_B    *Fields;    /* ptr to the start of fields    */
  1924. } LineFields;
  1925.  
  1926. extern int    ExtractFieldsFromLine (LineFields *);
  1927. extern Word_B    *SplitString (char *, Word_B *);
  1928.  
  1929. /*
  1930.  * Type of processing required by executable program.
  1931.  */
  1932.  
  1933. typedef struct ExecutableMode {
  1934.     char        *Name;
  1935.     unsigned int    Flags;
  1936.     unsigned char    FieldSep;
  1937. } ExeMode;
  1938.  
  1939. extern void        CheckProgramMode (char *, ExeMode *);
  1940. extern ExeMode        ExecProcessingMode; /* Current executable mode    */
  1941.  
  1942. /* Flags set a bit to indicate program mode */
  1943.  
  1944. #define EP_NONE        0x0000        /* Use PSP command line        */
  1945. #define EP_DOSMODE    0x0001        /* Use DOS mode extended line    */
  1946. #define EP_UNIXMODE    0x0002        /* Use UNIX mode extended line    */
  1947. #define EP_NOEXPAND    0x0004        /* Use -f for this command    */
  1948. #define EP_ENVIRON    0x0008        /* Use environ for variable    */
  1949. #define EP_NOSWAP    0x0010        /* Do not swap for this command    */
  1950. #define EP_EXPORT    0x0040        /* Use -m for this command    */
  1951. #define EP_CONVERT    0x0080        /* Use conversion        */
  1952. #define EP_NOWORDS    0x0100        /* Do word expansion        */
  1953. #define EP_NOQUOTE    0x0200        /* No quote protection        */
  1954. #define EP_IGNTYPE    0x0400        /* Ignore exe type (DOS only)    */
  1955. #define EP_PSEUDOTTY    0x0800        /* Child shells allow psuedo tty*/
  1956. #define EP_QUOTEWILD    0x1000        /* Quote wildcards        */
  1957.  
  1958. /*
  1959.  * storage allocation
  1960.  */
  1961.  
  1962. extern int    MemoryAreaLevel;    /* current allocation area */
  1963.  
  1964. /* Functions */
  1965.  
  1966. extern void    main (int, char **);
  1967.  
  1968. extern void    ShellErrorMessage (char *, ...);
  1969. extern void    PrintErrorMessage (char *, ...);
  1970. extern int    PrintWarningMessage (char *, ...);
  1971. extern void    CompilingError (void);
  1972.  
  1973. extern void    ExitTheShell (bool);
  1974. extern void    FinalExitCleanUp (int);
  1975.  
  1976. extern void    TerminateCurrentEnvironment (int);
  1977. extern void    CreateNewEnvironment (void);
  1978. extern void    QuitCurrentEnvironment (void);
  1979.  
  1980. extern void    InterruptSignalled (int);
  1981. extern void    TerminateSignalled (int);
  1982. extern void    RunTrapCommand (int);
  1983.  
  1984. extern void    SetShellSwitches (void);
  1985. extern Word_B    *AddWordToBlock (char *, Word_B *);
  1986. extern char    **GetWordList (Word_B *);
  1987. extern int    WordBlockSize (Word_B *);
  1988. extern char    *IntegerToString (int);
  1989. extern char    *GenerateTemporaryFileName (void);
  1990. extern int    (*IsCommandBuiltIn (char *, int *))(int, char **);
  1991. extern char    *BuildNextFullPathName (char *, char *, char *);
  1992. extern int    LookUpSymbol (char *);
  1993. extern int    GetNumericValue (char *);
  1994. extern bool    ConvertNumericValue (char *, long *, int);
  1995. extern char    *BuildFileName (char *);
  1996. extern int    CreateGlobalVariableList (unsigned int);
  1997. extern void    DeleteGlobalVariableList (void);
  1998. extern Word_B    *AddParameter (char *, Word_B *, char *);
  1999. extern char    *BuildOS2String (char **, char);
  2000. extern char    *GenerateFullExecutablePath (char *);
  2001.  
  2002. #if (OS_TYPE != OS_DOS)
  2003. extern char    *GetOSSystemErrorMessage (OSCALL_RET);
  2004. #endif
  2005.  
  2006. extern int    RestoreStandardIO (int, bool);
  2007. extern void    RestoreCurrentDirectory (char *);
  2008. extern bool    GotoDirectory (char *, unsigned int);
  2009. extern void    RestoreEnvironment (int, int);
  2010. extern bool    CheckForRestrictedShell (char *);
  2011. extern void    OutputUserPrompt (char *);
  2012. extern void    DisplayLineWithControl (char *);
  2013. extern void    GetCurrentDirectoryPath (void);
  2014. extern int    OpenForExecution (char *, char **, int *);
  2015. extern int    ProcessOutputMetaCharacters (char **);
  2016. extern char    *ConvertPathToFormat (char *, char, char);
  2017. extern int    CheckForScriptFile (char *, char **, int *);
  2018. extern void    PrintVersionNumber (FILE *);
  2019.  
  2020. /*
  2021.  * Smaller version of fputs & fputc
  2022.  */
  2023.  
  2024. extern int    feputs (char *);
  2025. extern int    foputs (char *);
  2026. extern int    feputc (int);
  2027.  
  2028. #if (OS_TYPE == OS_OS2) && (OS_SIZE == OS_32)
  2029. extern int    PrintTimes (void);
  2030. #endif
  2031.  
  2032. #if (OS_TYPE == OS_NT)
  2033. extern int    PrintTimes (void);
  2034. #endif
  2035.  
  2036. #ifdef OS_SWAPPING
  2037. extern void    ClearSwapFile (void);
  2038. #else
  2039. #  define ClearSwapFile()
  2040. #endif
  2041.  
  2042. extern void    ClearExtendedLineFile (void);
  2043.  
  2044. extern bool    GeneralPatternMatch (char *, unsigned char *, bool, char **,
  2045.                      int);
  2046. extern bool    SuffixPatternMatch (char *, char *, char **, int);
  2047. extern int    CountNumberArguments (char **);
  2048. extern int    SortCompare (const void *, const void *);
  2049.  
  2050. extern long    EvaluateMathsExpression (char *);
  2051. extern bool    ValidMathsExpression (char *, long *);
  2052.  
  2053. /*
  2054.  * Compiling and executing parse tree
  2055.  */
  2056.  
  2057. extern C_Op    *BuildParseTree (Source *);
  2058. extern int    ExecuteParseTree (C_Op *, int, int, int);
  2059. extern int    ScanNextToken (int);
  2060.  
  2061. #ifdef OS_SWAPPING
  2062. extern int    SA_spawn (char **);
  2063. #endif
  2064.  
  2065. extern int    ExecuteACommand (char **, int);
  2066. extern int    RunACommand (Source *, char **);
  2067. extern int    FindLocationOfExecutable (char *, char *);
  2068.  
  2069. extern int    ReMapIOHandler (int);
  2070.  
  2071. extern char    **ExpandWordList (char **, int, ExeMode *);
  2072. extern char    *ExpandAString (char *, int);
  2073. extern char    *substitute (char *, int);
  2074. extern char    *ExpandOneStringFirstComponent (char *, int);
  2075. extern char    **BuildCompletionList (char *, size_t, int *, bool);
  2076. extern size_t    GetCommonPartOfFileList (char **);
  2077.  
  2078. extern bool    ChangeInitialisationValue (char *, int);
  2079. extern void    Configure_Keys (void);
  2080.  
  2081. /*
  2082.  * Keyboard Input
  2083.  */
  2084.  
  2085. extern bool        RingWarningBell (void);
  2086. #if (OS_TYPE == OS_DOS)
  2087. extern unsigned char    Poll_Keyboard (void);
  2088. #else
  2089. #  define Poll_Keyboard()
  2090. #endif
  2091.  
  2092. extern void        PositionCursorInColumnZero (void);
  2093. extern int        GetConsoleInput (void);
  2094. extern int        GetDescriptorType (int);
  2095. extern bool        IsDirectory (char *);
  2096. extern int        GetEOFKey (void);
  2097. extern int        LookUpKeyBoardFunction (unsigned char, unsigned char);
  2098. extern int        ReadCursorPosition (void);
  2099. extern void        SetCursorPosition (int);
  2100. extern bool        ClearScreen (void);
  2101. extern void        PrintAList (int, char **);
  2102. extern void        GetScreenParameters (void);
  2103. extern void        SetCursorShape (bool);
  2104. extern void        EMACS_Initialisation (void);
  2105.  
  2106. /* read the keyboard */
  2107.  
  2108. extern unsigned char    ReadKeyBoard (unsigned char *);
  2109.  
  2110. #define KT_FUNCTION    0            /* Functionkey        */
  2111. #define KT_ALTFUNCTION    0xff            /* ALT key pressed    */
  2112. #define KT_RESIZE    0xfe            /* Window re-sized    */
  2113.  
  2114. #if defined (FLAGS_EMACS) || defined (FLAGS_VI) || defined (FLAGS_GMACS)
  2115. extern int        EditorInput (void);
  2116. #endif
  2117.  
  2118. #if defined (FLAGS_EMACS) || defined (FLAGS_GMACS)
  2119. extern int        BindKeyStroke (char *, char *, bool);
  2120. extern unsigned char    GetFunctionKeyMap (int, unsigned char *);
  2121. #endif
  2122.  
  2123. /*
  2124.  * Keyboard functions
  2125.  */
  2126.  
  2127. #define KF_SCANBACKWARD    0x00        /* Scan backwards in history    */
  2128. #define KF_SCANFOREWARD    0x01        /* Scan forewards in history    */
  2129. #define KF_PREVIOUS    0x02        /* Previous command        */
  2130. #define KF_NEXT        0x03        /* Next command            */
  2131. #define KF_LEFT        0x04        /* Left one character        */
  2132. #define KF_RIGHT    0x05        /* Right one character        */
  2133. #define KF_WORDRIGHT    0x06        /* Right one word        */
  2134. #define KF_WORDLEFT    0x07        /* Left one word        */
  2135. #define KF_START    0x08        /* Move to start of line    */
  2136. #define KF_CLEAR    0x09        /* Clear input line        */
  2137. #define KF_FLUSH    0x0a        /* Flush to end of line        */
  2138. #define KF_END        0x0b        /* End of line            */
  2139. #define KF_INSERT    0x0c        /* Insert mode switch        */
  2140. #define KF_DELETERIGHT    0x0d        /* Delete right character    */
  2141. #define KF_DELETELEFT    0x0e        /* Delete left character    */
  2142. #define KF_COMPLETE    0x0f        /* Complete file name        */
  2143. #define KF_DIRECTORY    0x10        /* Complete directory function    */
  2144. #define KF_CLEARSCREEN    0x11        /* Clear screen            */
  2145. #define KF_JOBS        0x12        /* Print Job tree        */
  2146. #define KF_TRANSPOSE    0x13        /* Transpose characters        */
  2147. #define KF_QUOTE    0x14        /* Quote character        */
  2148. #define KF_END_FKEYS    0x15        /* End of function keys        */
  2149.  
  2150. /*
  2151.  * Other init file codes
  2152.  */
  2153.  
  2154. #define KF_RINGBELL    0x15        /* Ring bell            */
  2155. #define KF_HALFHEIGTH    0x16        /* Half height cursor        */
  2156. #define KF_INSERTMODE    0x17        /* Overstrike or Insert        */
  2157. #define KF_INSERTCURSOR    0x18        /* Enable insert cursor        */
  2158. #define KF_ROOTDRIVE    0x19        /* Root drive            */
  2159. #define KF_EOFKEY    0x1a        /* EOF value            */
  2160.  
  2161. /*
  2162.  * Variable Name functions
  2163.  */
  2164.  
  2165. extern void        UnSetVariable (char *, int, bool);
  2166. extern void        SetVariableStatus (char *, int);
  2167. extern void        SetVariableArrayStatus (char *, int, int);
  2168. extern void        ClearVariableStatus (char *, int);
  2169. extern char        *GetVariableAsString (char *, bool);
  2170. extern char        *GetVariableArrayAsString (char *, int, bool);
  2171. extern long        GetVariableAsNumeric (char *);
  2172. extern long        GetVariableArrayAsNumeric (char *, int);
  2173. extern int        CountVariableArraySize (char *);
  2174. extern void        SetVariableFromString (char *, char *);
  2175. extern void        SetVariableArrayFromString (char *, int, char *);
  2176. extern void        SetVariableFromNumeric (char *, long);
  2177. extern void        SetVariableArrayFromNumeric (char *, int, long);
  2178. extern void        HandleSECONDandRANDOM (void);
  2179. extern bool        AssignVariableFromString (char *, int *);
  2180. extern bool        GetVariableName (char *, long *, char **, bool *);
  2181. extern char        IsValidVariableName (char *);
  2182. extern VariableList    *LookUpVariable (char *, int, bool);
  2183. extern int        SearchVariable (const void *, const void *);
  2184. extern void        BuildExtensionLists (void);
  2185.  
  2186. /*
  2187.  * Some missing EMX functions
  2188.  */
  2189.  
  2190. #if defined (__EMX__)
  2191. extern char        *ltoa (long, char *, int);
  2192. extern int        cwait (int *, int, int);
  2193. #endif
  2194.  
  2195. /*
  2196.  * Memory management
  2197.  */
  2198.  
  2199. extern char        *AllocateMemoryCell (size_t);
  2200. extern void        ReleaseMemoryCell (void *);
  2201. extern void        ReleaseAList (char **);
  2202. extern void        ReleaseMemoryArea (int);
  2203. extern void        SetMemoryAreaNumber (void *, int);
  2204. extern int        GetMemoryAreaNumber (void *);
  2205. extern void        *DuplicateMemoryCell (void *);
  2206. extern void        *GetAllocatedSpace (size_t);
  2207. extern void        *ReAllocateSpace (void *, size_t);
  2208. extern char        *StringSave (char *);
  2209. extern char        *StringCopy (char *);
  2210. extern size_t        GetMemoryCellSize (void *);
  2211.  
  2212. #ifdef DEBUG_MEMORY
  2213. extern void        DumpMemoryCells (int);
  2214. #define exit(x)        DumpMemoryCells (x)
  2215. #endif
  2216.  
  2217. /*
  2218.  * UNIX File I/O function emulation
  2219.  */
  2220.  
  2221. extern int        S_open (bool, char *, int);
  2222. extern int        S_close (int, bool);
  2223. extern void        S_fclose (FILE *, bool);
  2224. extern bool        S_stat (char *, struct stat *);
  2225. extern int        S_dup (int);
  2226. extern int        S_dup2 (int, int);
  2227. extern bool        S_access (char *, int);
  2228. extern bool        S_chdir (char *);
  2229. extern bool        S_getcwd (char *, int);
  2230. extern int        S_Remap (int, int);
  2231. extern int        OpenAPipe (void);
  2232. extern void        CloseThePipe (int);
  2233. extern void        CloseAllHandlers (void);
  2234.  
  2235. #if (OS_TYPE == OS_UNIX)
  2236. #  define CheckDOSFileName(a)    (a)
  2237. #  define GetCurrentDrive()    0
  2238. #  define SetCurrentDrive(a)    -1
  2239. #  define GetDriveLetter(a)    0
  2240. #  define GetDriveNumber(a)    0
  2241. #  define GetRootDiskDrive()    0
  2242. #else
  2243. extern char        *CheckDOSFileName (char *);
  2244. extern unsigned int    GetCurrentDrive (void);
  2245. extern int        SetCurrentDrive (unsigned int);
  2246. extern char         GetDriveLetter (unsigned int);
  2247. extern unsigned int    GetDriveNumber (char);
  2248. extern int        GetRootDiskDrive (void);
  2249. #endif
  2250.  
  2251. extern int        CloseFile (FILE *);
  2252. extern FILE        *FOpenFile (char *, char *);
  2253. extern FILE        *ReOpenFile (int, char *);
  2254. extern void        FlushStreams (void);
  2255. extern void        ChangeFileDescriptorStatus (int, bool);
  2256.  
  2257. /*
  2258.  * Shell Functions
  2259.  */
  2260.  
  2261. #define PF_MODE_NORMAL    0        /* Normal command        */
  2262. #define PF_MODE_ASYNC    1        /* Async command        */
  2263. #define PF_MODE_COPROC    2        /* Co-process command        */
  2264. #define PF_MODE_NO    3        /* No mode            */
  2265.  
  2266. extern FunctionList    *LookUpFunction (char *, bool);
  2267. extern bool        SaveFunction (C_Op *);
  2268. extern void        DeleteFunction (C_Op *);
  2269. extern void        PrintFunction (C_Op *, int);
  2270. extern C_Op        *CopyFunction (C_Op *);
  2271. extern int        PrintAllFunctions (void);
  2272. extern void        DeleteAllFunctions (void);
  2273.  
  2274. /*
  2275.  * Alias processing
  2276.  */
  2277.  
  2278. extern AliasList    *LookUpAlias (char *, bool);
  2279. extern void        DeleteAlias (char *);
  2280. extern bool        SaveAlias (char *, char *, bool);
  2281. extern void        PrintAlias (char *);
  2282. extern bool        IsValidAliasName (char *, bool);
  2283. extern void        UnTrackAllAliases (void);
  2284. extern int        PrintAllAlias (bool);
  2285.  
  2286. /*
  2287.  * Here document processing
  2288.  */
  2289.  
  2290. extern void        ScrapHereList (void);
  2291. extern void        FreeAllHereDocuments (int);
  2292. extern void        SaveHereDocumentInfo (IO_Actions *);
  2293. extern int        OpenHereFile (char *, bool);
  2294.  
  2295. /*
  2296.  * Job Processing
  2297.  */
  2298.  
  2299. #if (OS_TYPE != OS_DOS)
  2300. extern int        AddNewJob (PID, unsigned short, char *);
  2301. extern void        DeleteJob (PID);
  2302. extern void        DeleteJobBySession (unsigned short);
  2303. extern int        PrintJobs (bool);
  2304. extern int        NumberOfActiveJobs (void);
  2305. extern JobList        *LookUpJob (int);
  2306. extern JobList        *SearchForJob (char *);
  2307. extern int        PrintProcessTree (pid_t);
  2308. #endif
  2309.  
  2310. /*
  2311.  * History Processing
  2312.  */
  2313.  
  2314. extern void        AddHistory (bool);
  2315. extern void        LoadHistory (void);
  2316. extern void        DumpHistory (void);
  2317. extern void        ClearHistory (void);
  2318. extern void        PrintHistory (bool, bool, int, int, FILE *);
  2319. extern int        GetLastHistoryEvent (void);
  2320. extern int        GetFirstHistoryEvent (void);
  2321. extern char        *GetHistoryRecord (int);
  2322.  
  2323. #if (OS_TYPE != OS_DOS)
  2324. extern char        *GetLastHistoryString (void);
  2325. #endif
  2326.  
  2327. extern int        SearchHistory (char *);
  2328. extern void        FlushHistoryBuffer (void);
  2329. extern void        DeleteLastHistory (void);
  2330. extern char        CleanUpBuffer (int, char *, int);
  2331.  
  2332. /*
  2333.  * Interrupt handling
  2334.  */
  2335.  
  2336. #if (OS_TYPE == OS_DOS)
  2337. #  if (OS_SIZE == OS_16)
  2338. extern void interrupt far SW_Int24 (void);    /* Int 24 New address    */
  2339. extern void interrupt far SW_Int23 (void);    /* Int 23 New address    */
  2340. extern void interrupt far SW_Int00 (void);    /* Int 00 New address    */
  2341. extern bool far        SW_I23_InShell;        /* In the shell        */
  2342. #  elif !defined (__EMX__)
  2343. extern int    __far    HardErrorHandler (unsigned int, unsigned int,
  2344.                       unsigned int *);
  2345. #  endif
  2346. #endif
  2347.  
  2348. #if (OS_TYPE == OS_DOS)
  2349. #  if defined (__TURBOC__)
  2350. #    define GetInterruptVector(x)    (void (interrupt far *)())getvect ((x))
  2351. #    define SetInterruptVector(x,y)    setvect ((x), (y))
  2352. #  else
  2353. #    define GetInterruptVector(x)    _dos_getvect ((x))
  2354. #    define SetInterruptVector(x,y)    _dos_setvect ((x), (y))
  2355. #  endif
  2356. #endif
  2357.  
  2358. /*
  2359.  * XMS Driver functions
  2360.  */
  2361.  
  2362. #ifdef OS_SWAPPING
  2363. extern unsigned long far SW_XMS_Driver;        /* XMS Driver Interface    */
  2364. extern int        SW_XMS_Gversion (void);
  2365. extern int        SW_XMS_Allocate (unsigned int);
  2366. extern int        SW_XMS_Free (int);
  2367. extern int        SW_XMS_Available (void);
  2368. #endif
  2369.  
  2370. /*
  2371.  * Modified getopt for shell
  2372.  */
  2373.  
  2374. extern int        OptionIndex;        /* optind        */
  2375. extern int        OptionStart;        /* start character    */
  2376. extern char        *OptionArgument;    /* optarg        */
  2377.  
  2378. extern int        GetOptions (int, char **, char *, int);
  2379. extern void        ResetGetOptions (void);
  2380.  
  2381. /*
  2382.  * Save structure for getopts command
  2383.  */
  2384.  
  2385. typedef struct GetoptsIndex {
  2386.     int        Index;
  2387.     int        SubIndex;
  2388. } GetoptsIndex;
  2389.  
  2390. extern void        ResetGetoptsValues (bool);
  2391. extern void        GetGetoptsValues (GetoptsIndex *);
  2392. extern void        SaveGetoptsValues (int, int);
  2393.  
  2394. /*
  2395.  * General Functions
  2396.  */
  2397.  
  2398.  
  2399. /*
  2400.  * Flag values
  2401.  */
  2402.  
  2403. #define GETOPT_PLUS    0x01        /* Allow plus sign        */
  2404. #define GETOPT_MESSAGE    0x02        /* Print error message        */
  2405. #define GETOPT_PRINT    0x04        /* doecho special        */
  2406. #define GETOPT_AMISSING    0x08        /* doset special        */
  2407.  
  2408. /*
  2409.  * TSEARCH Functions
  2410.  */
  2411.  
  2412. typedef enum { preorder, postorder, endorder, leaf }    VISIT;
  2413.  
  2414. /*
  2415.  * Tree functions
  2416.  */
  2417.  
  2418. extern void    *tsearch (void *, void **, int (*)(const void *, const void *));
  2419. extern void    *tfind (void *, void **, int (*)(const void *, const void *));
  2420. extern void    *tdelete (void *, void **, int (*)(const void *, const void *));
  2421. extern void    twalk (const void *, void (*)(const void *, VISIT, int));
  2422.  
  2423. /*
  2424.  * DEBUG
  2425.  */
  2426.  
  2427. #ifdef DEBUG_ON
  2428. #  define DPRINT(a,b)    db_printf b
  2429. extern void        db_printf (char *, ...);
  2430. #else
  2431. #  define DPRINT(a,b)
  2432. #endif
  2433.